Chilkat Online Tools

Android / Plivo REST API / Get Call Detail Record (CDR) of a call

Back to Collection Items

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    CkHttp http = new CkHttp();
    boolean success;

    http.put_BasicAuth(true);
    http.put_Login("{{auth_id}}");
    http.put_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"
    // }

    CkJsonObject json = new CkJsonObject();
    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");

    CkStringBuilder sbRequestBody = new CkStringBuilder();
    json.EmitSb(sbRequestBody);

    CkHttpResponse resp = http.PTextSb("GET","https://api.plivo.com/v1/Account/<auth_id>/Call/{call_uuid}/",sbRequestBody,"utf-8","application/json",false,false);
    if (http.get_LastMethodSuccess() == false) {
        Log.i(TAG, http.lastErrorText());
        return;
        }

    Log.i(TAG, String.valueOf(resp.get_StatusCode()));
    Log.i(TAG, resp.bodyStr());


  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

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}"
    }
  ]
}