Unicode C Dynamics CRM: Create a Phone Call

Back to Index

Creates a phone call record regarding the Fourth Coffee account (b6a19cdd-88df-e311-b8e5-6c3be5a8b200), regarding the "Faulty product catalog" incident (c49e62a8-90df-e311-9565-a45d36fc5fe8), from the system user Allie Bellew (832698d1-b86a-47b5-a9a3-0cc710eb22e4), to the contact Gabriele Cannata (57a0e5b9-88df-e311-b8e5-6c3be5a8b200). A successful response is indicated by a 204 response status code with no response body.

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

CURL Command

curl -X POST https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/phonecalls \
  -H "Accept: application/json" \
  -H "Content-Type: application/json; charset=utf-8" \
  -H "OData-MaxVersion: 4.0"  \
  -H "OData-Version: 4.0" \
  -H "Authorization: Bearer DYNAMICS_CRM_ACCESS_TOKEN" \
  -d '{
    "subject": "Sample Phone Call 123",
    "phonenumber": "3125551920",
    "description": "Sample phone call created using the Chilkat Rest API",
    "scheduledend": "2018-04-29T11:56:21Z",
    "regardingobjectid_account@odata.bind": "/accounts(b6a19cdd-88df-e311-b8e5-6c3be5a8b200)",
    "actualdurationminutes": 25,
    "directioncode": true,
    "phonecall_activity_parties": [
        {   "partyid_systemuser@odata.bind": "/systemusers(832698d1-b86a-47b5-a9a3-0cc710eb22e4)",
            "participationtypemask": 1 },
        {   "partyid_contact@odata.bind": "/contacts(57a0e5b9-88df-e311-b8e5-6c3be5a8b200)",
            "participationtypemask": 2 },
        {   "partyid_incident@odata.bind": "/incidents(c49e62a8-90df-e311-9565-a45d36fc5fe8)",
            "participationtypemask": 8 }
    ]
}'

Unicode C Example

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

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    HCkJsonObjectW json;
    HCkStringBuilderW sbRequestBody;
    HCkStringBuilderW sbResponseBody;
    int respStatusCode;

    rest = CkRestW_Create();

    //  URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/phonecalls
    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;
    }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"subject",L"Sample Phone Call 123");
    CkJsonObjectW_UpdateString(json,L"phonenumber",L"3125551920");
    CkJsonObjectW_UpdateString(json,L"description",L"Sample phone call created using the Chilkat Rest API");
    CkJsonObjectW_UpdateString(json,L"scheduledend",L"2018-04-29T11:56:21Z");
    CkJsonObjectW_UpdateString(json,L"\"regardingobjectid_account@odata.bind\"",L"/accounts(b6a19cdd-88df-e311-b8e5-6c3be5a8b200)");
    CkJsonObjectW_UpdateNumber(json,L"actualdurationminutes",L"25");
    CkJsonObjectW_UpdateBool(json,L"directioncode",TRUE);
    CkJsonObjectW_UpdateString(json,L"phonecall_activity_parties[0].\"partyid_systemuser@odata.bind\"",L"/systemusers(832698d1-b86a-47b5-a9a3-0cc710eb22e4)");
    CkJsonObjectW_UpdateNumber(json,L"phonecall_activity_parties[0].participationtypemask",L"1");
    CkJsonObjectW_UpdateString(json,L"phonecall_activity_parties[1].\"partyid_contact@odata.bind\"",L"/contacts(57a0e5b9-88df-e311-b8e5-6c3be5a8b200)");
    CkJsonObjectW_UpdateNumber(json,L"phonecall_activity_parties[1].participationtypemask",L"2");
    CkJsonObjectW_UpdateString(json,L"phonecall_activity_parties[2].\"partyid_incident@odata.bind\"",L"/incidents(c49e62a8-90df-e311-9565-a45d36fc5fe8)");
    CkJsonObjectW_UpdateNumber(json,L"phonecall_activity_parties[2].participationtypemask",L"8");

    CkRestW_AddHeader(rest,L"Content-Type",L"application/json; charset=utf-8");
    CkRestW_AddHeader(rest,L"OData-Version",L"4.0");
    CkRestW_AddHeader(rest,L"Accept",L"application/json");
    CkRestW_AddHeader(rest,L"OData-MaxVersion",L"4.0");
    CkRestW_AddHeader(rest,L"Authorization",L"Bearer DYNAMICS_CRM_ACCESS_TOKEN");

    sbRequestBody = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(json,sbRequestBody);
    sbResponseBody = CkStringBuilderW_Create();
    success = CkRestW_FullRequestSb(rest,L"POST",L"/api/data/v9.0/phonecalls",sbRequestBody,sbResponseBody);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        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);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }



    CkRestW_Dispose(rest);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(sbRequestBody);
    CkStringBuilderW_Dispose(sbResponseBody);

    }