Xojo Plugin 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"

Xojo Plugin Example

Dim rest As New Chilkat.Rest
Dim success As Boolean

//  URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/phonecalls
Dim bTls As Boolean
bTls = True
Dim port As Int32
port = 443
Dim bAutoReconnect As Boolean
bAutoReconnect = True
success = rest.Connect("my-dynamics-domain.api.crm.dynamics.com",port,bTls,bAutoReconnect)
If (success <> True) Then
    System.DebugLog("ConnectFailReason: " + Str(rest.ConnectFailReason))
    System.DebugLog(rest.LastErrorText)
    Return
End If

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

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

Dim sbResponseBody As New Chilkat.StringBuilder
success = rest.FullRequestNoBodySb("GET","/api/data/v9.0/phonecalls",sbResponseBody)
If (success <> True) Then
    System.DebugLog(rest.LastErrorText)
    Return
End If

Dim respStatusCode As Int32
respStatusCode = rest.ResponseStatusCode
If (respStatusCode >= 400) Then
    System.DebugLog("Response Status Code = " + Str(respStatusCode))
    System.DebugLog("Response Header:")
    System.DebugLog(rest.ResponseHeader)
    System.DebugLog("Response Body:")
    System.DebugLog(sbResponseBody.GetAsString())
    Return
End If

Dim jsonResponse As New Chilkat.JsonObject
jsonResponse.LoadSb(sbResponseBody)

Dim i As Int32
Dim count_i As Int32

Dim odataContext As String
odataContext = jsonResponse.StringOf("""@odata.context""")
i = 0
count_i = jsonResponse.SizeOfArray("value")
While i < count_i
    jsonResponse.I = i
    Dim odataEtag As String
    odataEtag = jsonResponse.StringOf("value[i].""@odata.etag""")
    Dim subject As String
    subject = jsonResponse.StringOf("value[i].subject")
    Dim description As String
    description = jsonResponse.StringOf("value[i].description")
    Dim actualstart As String
    actualstart = jsonResponse.StringOf("value[i].actualstart")
    Dim activityid As String
    activityid = jsonResponse.StringOf("value[i].activityid")
    i = i + 1
Wend

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