Visual FoxPro 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"

Visual FoxPro Example

LOCAL loRest
LOCAL lnSuccess
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJsonResponse
LOCAL i
LOCAL lnCount_i
LOCAL lcOdataContext
LOCAL lcOdataEtag
LOCAL lcSubject
LOCAL lcDescription
LOCAL lcActualstart
LOCAL lcActivityid

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

loRest.AddQueryParam("$filter","_regardingobjectid_value eq b6a19cdd-88df-e311-b8e5-6c3be5a8b200")
loRest.AddQueryParam("$select","subject,description,actualstart,activityid")

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

loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestNoBodySb("GET","/api/data/v9.0/phonecalls",loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    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 loSbResponseBody
    CANCEL
ENDIF

loJsonResponse = CreateObject('Chilkat_9_5_0.JsonObject')
loJsonResponse.LoadSb(loSbResponseBody)

lcOdataContext = loJsonResponse.StringOf('"@odata.context"')
i = 0
lnCount_i = loJsonResponse.SizeOfArray("value")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lcOdataEtag = loJsonResponse.StringOf('value[i]."@odata.etag"')
    lcSubject = loJsonResponse.StringOf("value[i].subject")
    lcDescription = loJsonResponse.StringOf("value[i].description")
    lcActualstart = loJsonResponse.StringOf("value[i].actualstart")
    lcActivityid = loJsonResponse.StringOf("value[i].activityid")
    i = i + 1
ENDDO

RELEASE loRest
RELEASE loSbResponseBody
RELEASE loJsonResponse

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"
    }
  ]
}