PureBasic 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 }
    ]
}'

PureBasic Example

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkRest.pb"

Procedure ChilkatExample()

    rest.i = CkRest::ckCreate()
    If rest.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ;  URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/phonecalls
    bTls.i = 1
    port.i = 443
    bAutoReconnect.i = 1
    success = CkRest::ckConnect(rest,"my-dynamics-domain.api.crm.dynamics.com",port,bTls,bAutoReconnect)
    If success <> 1
        Debug "ConnectFailReason: " + Str(CkRest::ckConnectFailReason(rest))
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

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

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

    sbRequestBody.i = CkStringBuilder::ckCreate()
    If sbRequestBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckEmitSb(json,sbRequestBody)
    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkRest::ckFullRequestSb(rest,"POST","/api/data/v9.0/phonecalls",sbRequestBody,sbResponseBody)
    If success <> 1
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        CkJsonObject::ckDispose(json)
        CkStringBuilder::ckDispose(sbRequestBody)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    respStatusCode.i = CkRest::ckResponseStatusCode(rest)
    If respStatusCode >= 400
        Debug "Response Status Code = " + Str(respStatusCode)
        Debug "Response Header:"
        Debug CkRest::ckResponseHeader(rest)
        Debug "Response Body:"
        Debug CkStringBuilder::ckGetAsString(sbResponseBody)
        CkRest::ckDispose(rest)
        CkJsonObject::ckDispose(json)
        CkStringBuilder::ckDispose(sbRequestBody)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf



    CkRest::ckDispose(rest)
    CkJsonObject::ckDispose(json)
    CkStringBuilder::ckDispose(sbRequestBody)
    CkStringBuilder::ckDispose(sbResponseBody)


    ProcedureReturn
EndProcedure