Chilkat Online Tools

Node.js / Plivo REST API / Get Call Detail Record (CDR) of a call

Back to Collection Items

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node21-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node21-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node21-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node21-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node21-linux64');
    }
} else if (os.platform() == 'darwin') {
    if (os.arch() == 'arm64') {
        var chilkat = require('@chilkat/ck-node21-mac-m1');
    } else {
        var chilkat = require('@chilkat/ck-node21-macosx');
    }
}


function chilkatExample() {

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    var http = new chilkat.Http();
    var success;

    http.BasicAuth = true;
    http.Login = "{{auth_id}}";
    http.Password = "password";

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "legs": "aleg",
    //   "aleg_url": "https://aleg.url",
    //   "aleg_method": "POST",
    //   "bleg_url": "https://aleg.url",
    //   "bleg_method": "POST"
    // }

    var json = new chilkat.JsonObject();
    json.UpdateString("legs","aleg");
    json.UpdateString("aleg_url","https://aleg.url");
    json.UpdateString("aleg_method","POST");
    json.UpdateString("bleg_url","https://aleg.url");
    json.UpdateString("bleg_method","POST");

    var sbRequestBody = new chilkat.StringBuilder();
    json.EmitSb(sbRequestBody);

    // resp: HttpResponse
    var resp = http.PTextSb("GET","https://api.plivo.com/v1/Account/<auth_id>/Call/{call_uuid}/",sbRequestBody,"utf-8","application/json",false,false);
    if (http.LastMethodSuccess == false) {
        console.log(http.LastErrorText);
        return;
    }

    console.log(resp.StatusCode);
    console.log(resp.BodyStr);


}

chilkatExample();

Curl Command

curl -X GET
	-u '{{auth_id}}:password'
	-d '{
    "legs":"aleg",
    "aleg_url":"https://aleg.url",
    "aleg_method":"POST",
    "bleg_url":"https://aleg.url",
    "bleg_method":"POST"
}'
https://api.plivo.com/v1/Account/<auth_id>/Call/{call_uuid}/

Postman Collection Item JSON

{
  "name": "Get Call Detail Record (CDR) of a call",
  "protocolProfileBehavior": {
    "disableBodyPruning": true
  },
  "request": {
    "method": "GET",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"legs\":\"aleg\",\n    \"aleg_url\":\"https://aleg.url\",\n    \"aleg_method\":\"POST\",\n    \"bleg_url\":\"https://aleg.url\",\n    \"bleg_method\":\"POST\"\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "https://api.plivo.com/v1/Account/{{auth_id}}/Call/{call_uuid}/",
      "protocol": "https",
      "host": [
        "api",
        "plivo",
        "com"
      ],
      "path": [
        "v1",
        "Account",
        "{{auth_id}}",
        "Call",
        "{call_uuid}",
        ""
      ]
    },
    "description": "This method allows you to retrieve the Call Detail Record (CDR) of the call. More information can be found [here](https://www.plivo.com/docs/voice/api/call#retrieve-a-call)"
  },
  "response": [
    {
      "name": "Get Call Detail Record (CDR) of a call",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "https://api.plivo.com/v1/Account/{{auth_id}}/Call/{call_uuid}/",
          "protocol": "https",
          "host": [
            "api",
            "plivo",
            "com"
          ],
          "path": [
            "v1",
            "Account",
            "{{auth_id}}",
            "Call",
            "{call_uuid}",
            ""
          ]
        }
      },
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
      ],
      "cookie": [
      ],
      "body": "{\n    \"answer_time\": \"2015-07-26 15:45:02+05:30\",\n    \"api_id\": \"06ae0f8f-dc72-11e5-b56c-22000ae90795\",\n    \"bill_duration\": 924,\n    \"billed_duration\": 960,\n    \"call_direction\": \"outbound\",\n    \"call_duration\": 924,\n    \"call_uuid\": \"eba53b9e-8fbd-45c1-9444-696d2172fbc8\",\n    \"end_time\": \"2015-07-26 15:45:14+05:30\",\n    \"from_number\": \"+14158572518\",\n    \"initiation_time\": \"2015-07-26 15:44:49+05:30\",\n    \"parent_call_uuid\": null,\n    \"resource_uri\": \"/v1/Account/MAXXXXXXXXXXXXXXXXXX/Call/eba53b9e-8fbd-45c1-9444-696d2172fbc8/\",\n    \"to_number\": \"14153268174\",\n    \"total_amount\": \"0.13600\",\n    \"total_rate\": \"0.00850\",\n    \"hangup_cause_name\": \"End Of XML Instructions\",\n    \"hangup_cause_code\": 4010,\n    \"hangup_source\": \"Plivo\"\n}"
    }
  ]
}