PowerBuilder Dynamics CRM: Get Phone Calls Regarding an Account

Back to Index

Returns the subject, description, start date/time and activity ID for phone calls regarding an account. This example gets the phone calls regarding the Fourth Coffee account (accountid = b6a19cdd-88df-e311-b8e5-6c3be5a8b200).

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

CURL Command

curl -X GET https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/phonecalls \
  -H "Accept: application/json" \
  -H "OData-MaxVersion: 4.0"  \
  -H "OData-Version: 4.0" \
  -d "$filter=_regardingobjectid_value eq b6a19cdd-88df-e311-b8e5-6c3be5a8b200" \
  -d "$select=subject,description,actualstart,activityid" \
  -H "Authorization: Bearer DYNAMICS_CRM_ACCESS_TOKEN"

PowerBuilder Example

integer li_rc
oleobject loo_Rest
integer li_Success
integer li_BTls
integer li_Port
integer li_BAutoReconnect
oleobject loo_SbResponseBody
integer li_RespStatusCode
oleobject loo_JsonResponse
integer i
integer li_Count_i
string ls_OdataContext
string ls_OdataEtag
string ls_Subject
string ls_Description
string ls_Actualstart
string ls_Activityid

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_Rest.AddQueryParam("$filter","_regardingobjectid_value eq b6a19cdd-88df-e311-b8e5-6c3be5a8b200")
loo_Rest.AddQueryParam("$select","subject,description,actualstart,activityid")

loo_Rest.AddHeader("OData-MaxVersion","4.0")
loo_Rest.AddHeader("Accept","application/json")
loo_Rest.AddHeader("OData-Version","4.0")
loo_Rest.AddHeader("Authorization","Bearer DYNAMICS_CRM_ACCESS_TOKEN")

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

li_Success = loo_Rest.FullRequestNoBodySb("GET","/api/data/v9.0/phonecalls",loo_SbResponseBody)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    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_SbResponseBody
    return
end if

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

loo_JsonResponse.LoadSb(loo_SbResponseBody)

ls_OdataContext = loo_JsonResponse.StringOf("\"@odata.context\"")
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("value")
do while i < li_Count_i
    loo_JsonResponse.I = i
    ls_OdataEtag = loo_JsonResponse.StringOf("value[i].\"@odata.etag\"")
    ls_Subject = loo_JsonResponse.StringOf("value[i].subject")
    ls_Description = loo_JsonResponse.StringOf("value[i].description")
    ls_Actualstart = loo_JsonResponse.StringOf("value[i].actualstart")
    ls_Activityid = loo_JsonResponse.StringOf("value[i].activityid")
    i = i + 1
loop


destroy loo_Rest
destroy loo_SbResponseBody
destroy loo_JsonResponse

Sample JSON Response Body

{
  "@odata.context": "https://mydomain.api.crm.dynamics.com/api/data/v9.0/$metadata#phonecalls(subject,description,actualstart,activityid)",
  "value": [
    {
      "@odata.etag": "W/\"1818469\"",
      "subject": "Discussed coffee bean pricing.",
      "description": "Discussed coffee bean pricing.",
      "actualstart": "2018-04-29T11:56:21Z",
      "activityid": "098af854-a44b-e811-a955-000d3a1ca612"
    }
  ]
}