Visual FoxPro 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 }
    ]
}'

Visual FoxPro Example

LOCAL loRest
LOCAL lnSuccess
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loJson
LOCAL loSbRequestBody
LOCAL loSbResponseBody
LOCAL lnRespStatusCode

loRest = CreateObject('Chilkat_9_5_0.Rest')

*  URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/phonecalls
lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("my-dynamics-domain.api.crm.dynamics.com",lnPort,lnBTls,lnBAutoReconnect)
IF (lnSuccess <> 1) THEN
    ? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
ENDIF

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

loRest.AddHeader("Content-Type","application/json; charset=utf-8")
loRest.AddHeader("OData-Version","4.0")
loRest.AddHeader("Accept","application/json")
loRest.AddHeader("OData-MaxVersion","4.0")
loRest.AddHeader("Authorization","Bearer DYNAMICS_CRM_ACCESS_TOKEN")

loSbRequestBody = CreateObject('Chilkat_9_5_0.StringBuilder')
loJson.EmitSb(loSbRequestBody)
loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestSb("POST","/api/data/v9.0/phonecalls",loSbRequestBody,loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loJson
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

lnRespStatusCode = loRest.ResponseStatusCode
IF (lnRespStatusCode >= 400) THEN
    ? "Response Status Code = " + STR(lnRespStatusCode)
    ? "Response Header:"
    ? loRest.ResponseHeader
    ? "Response Body:"
    ? loSbResponseBody.GetAsString()
    RELEASE loRest
    RELEASE loJson
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

RELEASE loRest
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loSbResponseBody