Android™ Dynamics CRM: Get All Incidents (Cases) for an Account

Back to Index

Returns selected data for all cases (incidents) specific to the Fourth Coffee account (b6a19cdd-88df-e311-b8e5-6c3be5a8b200)

Documentation: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/incident?view=dynamics-ce-odata-9

CURL Command

curl -X GET https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/incidents \
  -H "Accept: application/json" \
  -H "OData-MaxVersion: 4.0"  \
  -H "OData-Version: 4.0" \
  -d "$select=title,prioritycode,severitycode,ticketnumber,createdon,followupby,resolveby" \
  -d "$expand=customerid_account($select=accountid,name)" \
  -d "$filter=customerid_account/accountid eq b6a19cdd-88df-e311-b8e5-6c3be5a8b200" \
  -H "Authorization: Bearer DYNAMICS_CRM_ACCESS_TOKEN"

Android™ Example

// 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);

    CkRest rest = new CkRest();
    boolean success;

    //  URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/incidents
    boolean bTls = true;
    int port = 443;
    boolean bAutoReconnect = true;
    success = rest.Connect("my-dynamics-domain.api.crm.dynamics.com",port,bTls,bAutoReconnect);
    if (success != true) {
        Log.i(TAG, "ConnectFailReason: " + String.valueOf(rest.get_ConnectFailReason()));
        Log.i(TAG, rest.lastErrorText());
        return;
        }

    rest.AddQueryParam("$select","title,prioritycode,severitycode,ticketnumber,createdon,followupby,resolveby");
    rest.AddQueryParam("$expand","customerid_account($select=accountid,name)");
    rest.AddQueryParam("$filter","customerid_account/accountid eq b6a19cdd-88df-e311-b8e5-6c3be5a8b200");

    rest.AddHeader("OData-MaxVersion","4.0");
    rest.AddHeader("Accept","application/json");
    rest.AddHeader("OData-Version","4.0");
    rest.AddHeader("Authorization","Bearer DYNAMICS_CRM_ACCESS_TOKEN");

    CkStringBuilder sbResponseBody = new CkStringBuilder();
    success = rest.FullRequestNoBodySb("GET","/api/data/v9.0/incidents",sbResponseBody);
    if (success != true) {
        Log.i(TAG, rest.lastErrorText());
        return;
        }

    int respStatusCode = rest.get_ResponseStatusCode();
    if (respStatusCode >= 400) {
        Log.i(TAG, "Response Status Code = " + String.valueOf(respStatusCode));
        Log.i(TAG, "Response Header:");
        Log.i(TAG, rest.responseHeader());
        Log.i(TAG, "Response Body:");
        Log.i(TAG, sbResponseBody.getAsString());
        return;
        }

    CkJsonObject jsonResponse = new CkJsonObject();
    jsonResponse.LoadSb(sbResponseBody);

    int i;
    int count_i;

    String odataContext = jsonResponse.stringOf("\"@odata.context\"");
    i = 0;
    count_i = jsonResponse.SizeOfArray("value");
    while (i < count_i) {
        jsonResponse.put_I(i);
        String odataEtag = jsonResponse.stringOf("value[i].\"@odata.etag\"");
        String title = jsonResponse.stringOf("value[i].title");
        int prioritycode = jsonResponse.IntOf("value[i].prioritycode");
        int severitycode = jsonResponse.IntOf("value[i].severitycode");
        String ticketnumber = jsonResponse.stringOf("value[i].ticketnumber");
        String createdon = jsonResponse.stringOf("value[i].createdon");
        String followupby = jsonResponse.stringOf("value[i].followupby");
        String resolveby = jsonResponse.stringOf("value[i].resolveby");
        String incidentid = jsonResponse.stringOf("value[i].incidentid");
        String customerid_accountAccountid = jsonResponse.stringOf("value[i].customerid_account.accountid");
        String customerid_accountName = jsonResponse.stringOf("value[i].customerid_account.name");
        i = i + 1;
        }


  }

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

Sample JSON Response Body

{
  "@odata.context": "https://mydomain.api.crm.dynamics.com/api/data/v9.0/$metadata#incidents(title,prioritycode,severitycode,ticketnumber,createdon,followupby,resolveby,customerid_account(accountid,name))",
  "value": [
    {
      "@odata.etag": "W/\"1161596\"",
      "title": "Faulty product catalog",
      "prioritycode": 2,
      "severitycode": 1,
      "ticketnumber": "CAS-01220-S1K8F4",
      "createdon": "2017-01-20T22:50:47Z",
      "followupby": "2015-06-04T16:15:42Z",
      "resolveby": "2015-06-05T16:15:42Z",
      "incidentid": "c49e62a8-90df-e311-9565-a45d36fc5fe8",
      "customerid_account": {
        "accountid": "b6a19cdd-88df-e311-b8e5-6c3be5a8b200",
        "name": "Fourth Coffee"
      }
    },
    {
      "@odata.etag": "W/\"1161597\"",
      "title": "Maintenance information for Desktop PCs.",
      "prioritycode": 3,
      "severitycode": 1,
      "ticketnumber": "CAS-01226-D5F0K2",
      "createdon": "2017-01-20T22:50:54Z",
      "followupby": "2015-06-04T23:15:46Z",
      "resolveby": "2015-06-05T23:15:46Z",
      "incidentid": "d09e62a8-90df-e311-9565-a45d36fc5fe8",
      "customerid_account": {
        "accountid": "b6a19cdd-88df-e311-b8e5-6c3be5a8b200",
        "name": "Fourth Coffee"
      }
    },
    {
      "@odata.etag": "W/\"1161598\"",
      "title": "Need service feature question",
      "prioritycode": 1,
      "severitycode": 1,
      "ticketnumber": "CAS-01232-S7L0X4",
      "createdon": "2017-01-20T22:50:57Z",
      "followupby": "2015-06-04T16:15:49Z",
      "resolveby": "2015-06-05T16:15:49Z",
      "incidentid": "dc9e62a8-90df-e311-9565-a45d36fc5fe8",
      "customerid_account": {
        "accountid": "b6a19cdd-88df-e311-b8e5-6c3be5a8b200",
        "name": "Fourth Coffee"
      }
    },
    {
      "@odata.etag": "W/\"1161599\"",
      "title": "Product catalog requested",
      "prioritycode": 3,
      "severitycode": 1,
      "ticketnumber": "CAS-01237-H0T7F2",
      "createdon": "2017-01-20T22:50:58Z",
      "followupby": null,
      "resolveby": null,
      "incidentid": "e69e62a8-90df-e311-9565-a45d36fc5fe8",
      "customerid_account": {
        "accountid": "b6a19cdd-88df-e311-b8e5-6c3be5a8b200",
        "name": "Fourth Coffee"
      }
    },
    {
      "@odata.etag": "W/\"1161600\"",
      "title": "Product service time inquiry",
      "prioritycode": 1,
      "severitycode": 1,
      "ticketnumber": "CAS-01249-V5V2X3",
      "createdon": "2017-01-20T22:51:04Z",
      "followupby": null,
      "resolveby": null,
      "incidentid": "fe9e62a8-90df-e311-9565-a45d36fc5fe8",
      "customerid_account": {
        "accountid": "b6a19cdd-88df-e311-b8e5-6c3be5a8b200",
        "name": "Fourth Coffee"
      }
    },
    {
      "@odata.etag": "W/\"1161601\"",
      "title": "Service required",
      "prioritycode": 1,
      "severitycode": 1,
      "ticketnumber": "CAS-01256-G9B1B1",
      "createdon": "2017-01-20T22:51:06Z",
      "followupby": "2015-06-04T16:16:06Z",
      "resolveby": "2015-06-05T16:16:06Z",
      "incidentid": "0c9f62a8-90df-e311-9565-a45d36fc5fe8",
      "customerid_account": {
        "accountid": "b6a19cdd-88df-e311-b8e5-6c3be5a8b200",
        "name": "Fourth Coffee"
      }
    },
    {
      "@odata.etag": "W/\"1161602\"",
      "title": "Shipping time information resend",
      "prioritycode": 3,
      "severitycode": 1,
      "ticketnumber": "CAS-01261-N0C8H9",
      "createdon": "2017-01-20T22:51:13Z",
      "followupby": "2015-06-04T16:16:09Z",
      "resolveby": "2015-06-05T16:16:10Z",
      "incidentid": "169f62a8-90df-e311-9565-a45d36fc5fe8",
      "customerid_account": {
        "accountid": "b6a19cdd-88df-e311-b8e5-6c3be5a8b200",
        "name": "Fourth Coffee"
      }
    }
  ]
}