Swift Dynamics CRM: Get All Information for a Specific Incident

Back to Index

Returns the entire JSON record for a specific incident.

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

CURL Command

curl -X GET https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/incidents \
  -H "Accept: application/json" \
  -H "OData-MaxVersion: 4.0"  \
  -H "OData-Version: 4.0" \
  -d "$expand=customerid_account($select=accountid,name)" \
  -d "$filter=incidentid eq c49e62a8-90df-e311-9565-a45d36fc5fe8" \
  -H "Authorization: Bearer DYNAMICS_CRM_ACCESS_TOKEN"

Swift Example


func chilkatTest() {
    let rest = CkoRest()
    var success: Bool

    //  URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/incidents
    var bTls: Bool = true
    var port: Int = 443
    var bAutoReconnect: Bool = true
    success = rest.Connect("my-dynamics-domain.api.crm.dynamics.com", port: port, tls: bTls, autoReconnect: bAutoReconnect)
    if success != true {
        print("ConnectFailReason: \(rest.ConnectFailReason.intValue)")
        print("\(rest.LastErrorText)")
        return
    }

    rest.AddQueryParam("$expand", value: "customerid_account($select=accountid,name)")
    rest.AddQueryParam("$filter", value: "incidentid eq c49e62a8-90df-e311-9565-a45d36fc5fe8")

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

    let sbResponseBody = CkoStringBuilder()
    success = rest.FullRequestNoBodySb("GET", uriPath: "/api/data/v9.0/incidents", sb: sbResponseBody)
    if success != true {
        print("\(rest.LastErrorText)")
        return
    }

    var respStatusCode: Int = rest.ResponseStatusCode.intValue
    if respStatusCode >= 400 {
        print("Response Status Code = \(respStatusCode)")
        print("Response Header:")
        print("\(rest.ResponseHeader)")
        print("Response Body:")
        print("\(sbResponseBody.GetAsString())")
        return
    }

    let jsonResponse = CkoJsonObject()
    jsonResponse.LoadSb(sbResponseBody)

    var i: Int
    var count_i: Int

    var odataContext: String? = jsonResponse.StringOf("\"@odata.context\"")
    i = 0
    count_i = jsonResponse.SizeOfArray("value").intValue
    while i < count_i {
        jsonResponse.I = i
        var odataEtag: String? = jsonResponse.StringOf("value[i].\"@odata.etag\"")
        var v_resolvebykpiid_value: String? = jsonResponse.StringOf("value[i]._resolvebykpiid_value")
        var customercontacted: Bool = jsonResponse.BoolOf("value[i].customercontacted")
        var v_accountid_value: String? = jsonResponse.StringOf("value[i]._accountid_value")
        var prioritycode: Int = jsonResponse.IntOf("value[i].prioritycode").intValue
        var v_msdyn_incidenttype_value: String? = jsonResponse.StringOf("value[i]._msdyn_incidenttype_value")
        var caseorigincode: Int = jsonResponse.IntOf("value[i].caseorigincode").intValue
        var modifiedon: String? = jsonResponse.StringOf("value[i].modifiedon")
        var v_parentcaseid_value: String? = jsonResponse.StringOf("value[i]._parentcaseid_value")
        var v_slainvokedid_value: String? = jsonResponse.StringOf("value[i]._slainvokedid_value")
        var overriddencreatedon: String? = jsonResponse.StringOf("value[i].overriddencreatedon")
        var isescalated: Bool = jsonResponse.BoolOf("value[i].isescalated")
        var int_paraturecasenumber: String? = jsonResponse.StringOf("value[i].int_paraturecasenumber")
        var checkemail: Bool = jsonResponse.BoolOf("value[i].checkemail")
        var followupby: String? = jsonResponse.StringOf("value[i].followupby")
        var ticketnumber: String? = jsonResponse.StringOf("value[i].ticketnumber")
        var versionnumber: Int = jsonResponse.IntOf("value[i].versionnumber").intValue
        var v_modifiedby_value: String? = jsonResponse.StringOf("value[i]._modifiedby_value")
        var billedserviceunits: String? = jsonResponse.StringOf("value[i].billedserviceunits")
        var decremententitlementterm: Bool = jsonResponse.BoolOf("value[i].decremententitlementterm")
        var onholdtime: String? = jsonResponse.StringOf("value[i].onholdtime")
        var resolveby: String? = jsonResponse.StringOf("value[i].resolveby")
        var int_upsellreferral: Bool = jsonResponse.BoolOf("value[i].int_upsellreferral")
        var messagetypecode: String? = jsonResponse.StringOf("value[i].messagetypecode")
        var emailaddress: String? = jsonResponse.StringOf("value[i].emailaddress")
        var merged: Bool = jsonResponse.BoolOf("value[i].merged")
        var int_surveryparticipation: String? = jsonResponse.StringOf("value[i].int_surveryparticipation")
        var contractservicelevelcode: String? = jsonResponse.StringOf("value[i].contractservicelevelcode")
        var v_createdonbehalfby_value: String? = jsonResponse.StringOf("value[i]._createdonbehalfby_value")
        var v_contactid_value: String? = jsonResponse.StringOf("value[i]._contactid_value")
        var v_existingcase_value: String? = jsonResponse.StringOf("value[i]._existingcase_value")
        var productserialnumber: String? = jsonResponse.StringOf("value[i].productserialnumber")
        var v_owninguser_value: String? = jsonResponse.StringOf("value[i]._owninguser_value")
        var int_effortnum: String? = jsonResponse.StringOf("value[i].int_effortnum")
        var escalatedon: String? = jsonResponse.StringOf("value[i].escalatedon")
        var v_productid_value: String? = jsonResponse.StringOf("value[i]._productid_value")
        var followuptaskcreated: Bool = jsonResponse.BoolOf("value[i].followuptaskcreated")
        var v_ownerid_value: String? = jsonResponse.StringOf("value[i]._ownerid_value")
        var new_actualsatisfaction: String? = jsonResponse.StringOf("value[i].new_actualsatisfaction")
        var v_socialprofileid_value: String? = jsonResponse.StringOf("value[i]._socialprofileid_value")
        var v_createdbyexternalparty_value: String? = jsonResponse.StringOf("value[i]._createdbyexternalparty_value")
        var v_contractid_value: String? = jsonResponse.StringOf("value[i]._contractid_value")
        var v_modifiedbyexternalparty_value: String? = jsonResponse.StringOf("value[i]._modifiedbyexternalparty_value")
        var v_masterid_value: String? = jsonResponse.StringOf("value[i]._masterid_value")
        var timezoneruleversionnumber: Int = jsonResponse.IntOf("value[i].timezoneruleversionnumber").intValue
        var entityimageid: String? = jsonResponse.StringOf("value[i].entityimageid")
        var v_primarycontactid_value: String? = jsonResponse.StringOf("value[i]._primarycontactid_value")
        var importsequencenumber: Int = jsonResponse.IntOf("value[i].importsequencenumber").intValue
        var v_owningteam_value: String? = jsonResponse.StringOf("value[i]._owningteam_value")
        var routecase: Bool = jsonResponse.BoolOf("value[i].routecase")
        var blockedprofile: Bool = jsonResponse.BoolOf("value[i].blockedprofile")
        var statecode: Int = jsonResponse.IntOf("value[i].statecode").intValue
        var int_casecategory: String? = jsonResponse.StringOf("value[i].int_casecategory")
        var entityimage_timestamp: String? = jsonResponse.StringOf("value[i].entityimage_timestamp")
        var firstresponseslastatus: Int = jsonResponse.IntOf("value[i].firstresponseslastatus").intValue
        var traversedpath: String? = jsonResponse.StringOf("value[i].traversedpath")
        var int_actualsatisfaction: String? = jsonResponse.StringOf("value[i].int_actualsatisfaction")
        var v_int_associatedproduct_value: String? = jsonResponse.StringOf("value[i]._int_associatedproduct_value")
        var v_customerid_value: String? = jsonResponse.StringOf("value[i]._customerid_value")
        var entityimage: String? = jsonResponse.StringOf("value[i].entityimage")
        var v_entitlementid_value: String? = jsonResponse.StringOf("value[i]._entitlementid_value")
        var activitiescomplete: Bool = jsonResponse.BoolOf("value[i].activitiescomplete")
        var new_upsellreferral: String? = jsonResponse.StringOf("value[i].new_upsellreferral")
        var statuscode: Int = jsonResponse.IntOf("value[i].statuscode").intValue
        var processid: String? = jsonResponse.StringOf("value[i].processid")
        var v_contractdetailid_value: String? = jsonResponse.StringOf("value[i]._contractdetailid_value")
        var int_customereffort: Int = jsonResponse.IntOf("value[i].int_customereffort").intValue
        var responseby: String? = jsonResponse.StringOf("value[i].responseby")
        var v_transactioncurrencyid_value: String? = jsonResponse.StringOf("value[i]._transactioncurrencyid_value")
        var sentimentvalue: String? = jsonResponse.StringOf("value[i].sentimentvalue")
        var v_slaid_value: String? = jsonResponse.StringOf("value[i]._slaid_value")
        var influencescore: String? = jsonResponse.StringOf("value[i].influencescore")
        var v_firstresponsebykpiid_value: String? = jsonResponse.StringOf("value[i]._firstresponsebykpiid_value")
        var utcconversiontimezonecode: String? = jsonResponse.StringOf("value[i].utcconversiontimezonecode")
        var numberofchildincidents: String? = jsonResponse.StringOf("value[i].numberofchildincidents")
        var incidentid: String? = jsonResponse.StringOf("value[i].incidentid")
        var new_casecategory: String? = jsonResponse.StringOf("value[i].new_casecategory")
        var v_owningbusinessunit_value: String? = jsonResponse.StringOf("value[i]._owningbusinessunit_value")
        var casetypecode: Int = jsonResponse.IntOf("value[i].casetypecode").intValue
        var resolvebyslastatus: Int = jsonResponse.IntOf("value[i].resolvebyslastatus").intValue
        var createdon: String? = jsonResponse.StringOf("value[i].createdon")
        var severitycode: Int = jsonResponse.IntOf("value[i].severitycode").intValue
        var exchangerate: String? = jsonResponse.StringOf("value[i].exchangerate")
        var v_subjectid_value: String? = jsonResponse.StringOf("value[i]._subjectid_value")
        var servicestage: Int = jsonResponse.IntOf("value[i].servicestage").intValue
        var description: String? = jsonResponse.StringOf("value[i].description")
        var lastonholdtime: String? = jsonResponse.StringOf("value[i].lastonholdtime")
        var actualserviceunits: String? = jsonResponse.StringOf("value[i].actualserviceunits")
        var title: String? = jsonResponse.StringOf("value[i].title")
        var v_createdby_value: String? = jsonResponse.StringOf("value[i]._createdby_value")
        var isdecrementing: Bool = jsonResponse.BoolOf("value[i].isdecrementing")
        var v_modifiedonbehalfby_value: String? = jsonResponse.StringOf("value[i]._modifiedonbehalfby_value")
        var customersatisfactioncode: Int = jsonResponse.IntOf("value[i].customersatisfactioncode").intValue
        var stageid: String? = jsonResponse.StringOf("value[i].stageid")
        var v_kbarticleid_value: String? = jsonResponse.StringOf("value[i]._kbarticleid_value")
        var entityimage_url: String? = jsonResponse.StringOf("value[i].entityimage_url")
        var firstresponsesent: Bool = jsonResponse.BoolOf("value[i].firstresponsesent")
        var incidentstagecode: Int = jsonResponse.IntOf("value[i].incidentstagecode").intValue
        var customerid_accountAccountid: String? = jsonResponse.StringOf("value[i].customerid_account.accountid")
        var customerid_accountName: String? = jsonResponse.StringOf("value[i].customerid_account.name")
        i = i + 1
    }


}

Sample JSON Response Body

{
  "@odata.context": "https://mydomain.api.crm.dynamics.com/api/data/v9.0/$metadata#incidents(customerid_account(accountid,name))",
  "value": [
    {
      "@odata.etag": "W/\"1161596\"",
      "_resolvebykpiid_value": null,
      "customercontacted": false,
      "_accountid_value": null,
      "prioritycode": 2,
      "_msdyn_incidenttype_value": null,
      "caseorigincode": 2,
      "modifiedon": "2018-03-03T12:34:48Z",
      "_parentcaseid_value": null,
      "_slainvokedid_value": null,
      "overriddencreatedon": "2018-03-03T12:34:48Z",
      "isescalated": false,
      "int_paraturecasenumber": null,
      "checkemail": false,
      "followupby": "2015-06-04T16:15:42Z",
      "ticketnumber": "CAS-01220-S1K8F4",
      "versionnumber": 1161596,
      "_modifiedby_value": "32ff7175-0dbe-4acb-872e-22f86435bf98",
      "billedserviceunits": null,
      "decremententitlementterm": true,
      "onholdtime": null,
      "resolveby": "2015-06-05T16:15:42Z",
      "int_upsellreferral": false,
      "messagetypecode": null,
      "emailaddress": null,
      "merged": false,
      "int_surveryparticipation": null,
      "contractservicelevelcode": null,
      "_createdonbehalfby_value": null,
      "_contactid_value": null,
      "_existingcase_value": null,
      "productserialnumber": null,
      "_owninguser_value": "32ff7175-0dbe-4acb-872e-22f86435bf98",
      "int_effortnum": null,
      "escalatedon": null,
      "_productid_value": "3509d8af-7bc3-e411-80df-fc15b42886e8",
      "followuptaskcreated": false,
      "_ownerid_value": "32ff7175-0dbe-4acb-872e-22f86435bf98",
      "new_actualsatisfaction": null,
      "_socialprofileid_value": null,
      "_createdbyexternalparty_value": null,
      "_contractid_value": null,
      "_modifiedbyexternalparty_value": null,
      "_masterid_value": null,
      "timezoneruleversionnumber": 0,
      "entityimageid": null,
      "_primarycontactid_value": null,
      "importsequencenumber": 124,
      "_owningteam_value": null,
      "routecase": true,
      "blockedprofile": false,
      "statecode": 0,
      "int_casecategory": null,
      "entityimage_timestamp": null,
      "firstresponseslastatus": 1,
      "traversedpath": null,
      "int_actualsatisfaction": null,
      "_int_associatedproduct_value": null,
      "_customerid_value": "b6a19cdd-88df-e311-b8e5-6c3be5a8b200",
      "entityimage": null,
      "_entitlementid_value": null,
      "activitiescomplete": false,
      "new_upsellreferral": null,
      "statuscode": 1,
      "processid": "0ffbcde4-61c1-4355-aa89-aa1d7b2b8792",
      "_contractdetailid_value": null,
      "int_customereffort": 121590000,
      "responseby": null,
      "_transactioncurrencyid_value": null,
      "sentimentvalue": null,
      "_slaid_value": null,
      "influencescore": null,
      "_firstresponsebykpiid_value": null,
      "utcconversiontimezonecode": null,
      "numberofchildincidents": null,
      "incidentid": "c49e62a8-90df-e311-9565-a45d36fc5fe8",
      "new_casecategory": null,
      "_owningbusinessunit_value": "c4106190-c81e-e811-a980-000d3a192e9a",
      "casetypecode": 2,
      "resolvebyslastatus": 1,
      "createdon": "2017-01-20T22:50:47Z",
      "severitycode": 1,
      "exchangerate": null,
      "_subjectid_value": "191de3d1-21d5-e411-80eb-c4346bad3638",
      "servicestage": 0,
      "description": null,
      "lastonholdtime": null,
      "actualserviceunits": null,
      "title": "Faulty product catalog",
      "_createdby_value": "32ff7175-0dbe-4acb-872e-22f86435bf98",
      "isdecrementing": false,
      "_modifiedonbehalfby_value": null,
      "customersatisfactioncode": 3,
      "stageid": "92a6721b-d465-4d36-aef7-e8822d7a5a6a",
      "_kbarticleid_value": null,
      "entityimage_url": null,
      "firstresponsesent": false,
      "incidentstagecode": 1,
      "customerid_account": {
        "accountid": "b6a19cdd-88df-e311-b8e5-6c3be5a8b200",
        "name": "Fourth Coffee"
      }
    }
  ]
}