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

PowerBuilder Example

integer li_rc
oleobject loo_Rest
integer li_Success
integer li_BTls
integer li_Port
integer li_BAutoReconnect
oleobject loo_Json
oleobject loo_SbRequestBody
oleobject loo_SbResponseBody
integer li_RespStatusCode

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat_9_5_0.Rest")
if li_rc < 0 then
    destroy loo_Rest
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/phonecalls
li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("my-dynamics-domain.api.crm.dynamics.com",li_Port,li_BTls,li_BAutoReconnect)
if li_Success <> 1 then
    Write-Debug "ConnectFailReason: " + string(loo_Rest.ConnectFailReason)
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    return
end if

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

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

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

loo_SbRequestBody = create oleobject
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Json.EmitSb(loo_SbRequestBody)
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

li_Success = loo_Rest.FullRequestSb("POST","/api/data/v9.0/phonecalls",loo_SbRequestBody,loo_SbResponseBody)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_Json
    destroy loo_SbRequestBody
    destroy loo_SbResponseBody
    return
end if

li_RespStatusCode = loo_Rest.ResponseStatusCode
if li_RespStatusCode >= 400 then
    Write-Debug "Response Status Code = " + string(li_RespStatusCode)
    Write-Debug "Response Header:"
    Write-Debug loo_Rest.ResponseHeader
    Write-Debug "Response Body:"
    Write-Debug loo_SbResponseBody.GetAsString()
    destroy loo_Rest
    destroy loo_Json
    destroy loo_SbRequestBody
    destroy loo_SbResponseBody
    return
end if



destroy loo_Rest
destroy loo_Json
destroy loo_SbRequestBody
destroy loo_SbResponseBody