Python Dynamics CRM: Find Tasks for an Incident

Back to Index

Returns tasks for a specific incident.

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

CURL Command

curl -X GET https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/tasks \
  -H "Accept: application/json" \
  -H "OData-MaxVersion: 4.0"  \
  -H "OData-Version: 4.0" \
  -d "$select=subject,description,actualstart,activityid,_regardingobjectid_value" \
  -d "$filter=regardingobjectid_incident/incidentid eq c49e62a8-90df-e311-9565-a45d36fc5fe8" \
  -H "Authorization: Bearer DYNAMICS_CRM_ACCESS_TOKEN"

Python Example

import sys
import chilkat

rest = chilkat.CkRest()

#  URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/tasks
bTls = True
port = 443
bAutoReconnect = True
success = rest.Connect("my-dynamics-domain.api.crm.dynamics.com",port,bTls,bAutoReconnect)
if (success != True):
    print("ConnectFailReason: " + str(rest.get_ConnectFailReason()))
    print(rest.lastErrorText())
    sys.exit()

rest.AddQueryParam("$select","subject,description,actualstart,activityid,_regardingobjectid_value")
rest.AddQueryParam("$filter","regardingobjectid_incident/incidentid eq c49e62a8-90df-e311-9565-a45d36fc5fe8")

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")

sbResponseBody = chilkat.CkStringBuilder()
success = rest.FullRequestNoBodySb("GET","/api/data/v9.0/tasks",sbResponseBody)
if (success != True):
    print(rest.lastErrorText())
    sys.exit()

respStatusCode = rest.get_ResponseStatusCode()
if (respStatusCode >= 400):
    print("Response Status Code = " + str(respStatusCode))
    print("Response Header:")
    print(rest.responseHeader())
    print("Response Body:")
    print(sbResponseBody.getAsString())
    sys.exit()

jsonResponse = chilkat.CkJsonObject()
jsonResponse.LoadSb(sbResponseBody)

odataContext = jsonResponse.stringOf("\"@odata.context\"")
i = 0
count_i = jsonResponse.SizeOfArray("value")
while i < count_i :
    jsonResponse.put_I(i)
    odataEtag = jsonResponse.stringOf("value[i].\"@odata.etag\"")
    subject = jsonResponse.stringOf("value[i].subject")
    description = jsonResponse.stringOf("value[i].description")
    actualstart = jsonResponse.stringOf("value[i].actualstart")
    activityid = jsonResponse.stringOf("value[i].activityid")
    v_regardingobjectid_value = jsonResponse.stringOf("value[i]._regardingobjectid_value")
    i = i + 1

Sample JSON Response Body

{
  "@odata.context": "https://mydomain.api.crm.dynamics.com/api/data/v9.0/$metadata#tasks(subject,description,actualstart,activityid,_regardingobjectid_value)",
  "value": [
    {
      "@odata.etag": "W/\"1173836\"",
      "subject": "Feedback on the product catalog",
      "description": "Defined and captured critical customer requirements for the product catalog. Reviewed the draft content with key players on the committee; recorded attendees. Generated email using the relevant template.",
      "actualstart": null,
      "activityid": "ca81ac0c-91df-e311-b8e5-6c3be5a8b200",
      "_regardingobjectid_value": "c49e62a8-90df-e311-9565-a45d36fc5fe8"
    }
  ]
}