Unicode C Dynamics CRM: Find Tasks for an Incident

Back to Index

Returns tasks for a specific incident.

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

CURL Command

curl -X GET https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/tasks \
  -H "Accept: application/json" \
  -H "OData-MaxVersion: 4.0"  \
  -H "OData-Version: 4.0" \
  -d "$select=subject,description,actualstart,activityid,_regardingobjectid_value" \
  -d "$filter=regardingobjectid_incident/incidentid eq c49e62a8-90df-e311-9565-a45d36fc5fe8" \
  -H "Authorization: Bearer DYNAMICS_CRM_ACCESS_TOKEN"

Unicode C Example

#include <C_CkRestW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    HCkStringBuilderW sbResponseBody;
    int respStatusCode;
    HCkJsonObjectW jsonResponse;
    int i;
    int count_i;
    const wchar_t *odataContext;
    const wchar_t *odataEtag;
    const wchar_t *subject;
    const wchar_t *description;
    const wchar_t *actualstart;
    const wchar_t *activityid;
    const wchar_t *v_regardingobjectid_value;

    rest = CkRestW_Create();

    //  URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/tasks
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"my-dynamics-domain.api.crm.dynamics.com",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    CkRestW_AddQueryParam(rest,L"$select",L"subject,description,actualstart,activityid,_regardingobjectid_value");
    CkRestW_AddQueryParam(rest,L"$filter",L"regardingobjectid_incident/incidentid eq c49e62a8-90df-e311-9565-a45d36fc5fe8");

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

    sbResponseBody = CkStringBuilderW_Create();
    success = CkRestW_FullRequestNoBodySb(rest,L"GET",L"/api/data/v9.0/tasks",sbResponseBody);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    respStatusCode = CkRestW_getResponseStatusCode(rest);
    if (respStatusCode >= 400) {
        wprintf(L"Response Status Code = %d\n",respStatusCode);
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkRestW_responseHeader(rest));
        wprintf(L"Response Body:\n");
        wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponseBody));
        CkRestW_Dispose(rest);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jsonResponse = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jsonResponse,sbResponseBody);

    odataContext = CkJsonObjectW_stringOf(jsonResponse,L"\"@odata.context\"");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"value");
    while (i < count_i) {
        CkJsonObjectW_putI(jsonResponse,i);
        odataEtag = CkJsonObjectW_stringOf(jsonResponse,L"value[i].\"@odata.etag\"");
        subject = CkJsonObjectW_stringOf(jsonResponse,L"value[i].subject");
        description = CkJsonObjectW_stringOf(jsonResponse,L"value[i].description");
        actualstart = CkJsonObjectW_stringOf(jsonResponse,L"value[i].actualstart");
        activityid = CkJsonObjectW_stringOf(jsonResponse,L"value[i].activityid");
        v_regardingobjectid_value = CkJsonObjectW_stringOf(jsonResponse,L"value[i]._regardingobjectid_value");
        i = i + 1;
    }



    CkRestW_Dispose(rest);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jsonResponse);

    }

Sample JSON Response Body

{
  "@odata.context": "https://mydomain.api.crm.dynamics.com/api/data/v9.0/$metadata#tasks(subject,description,actualstart,activityid,_regardingobjectid_value)",
  "value": [
    {
      "@odata.etag": "W/\"1173836\"",
      "subject": "Feedback on the product catalog",
      "description": "Defined and captured critical customer requirements for the product catalog. Reviewed the draft content with key players on the committee; recorded attendees. Generated email using the relevant template.",
      "actualstart": null,
      "activityid": "ca81ac0c-91df-e311-b8e5-6c3be5a8b200",
      "_regardingobjectid_value": "c49e62a8-90df-e311-9565-a45d36fc5fe8"
    }
  ]
}