C# Dynamics CRM: Retrieve a Single Contact

Back to Index

Returns the full contact record for a given contactid.

Documentation: https://msdn.microsoft.com/en-us/library/gg334767.aspx#Basic query example

CURL Command

curl -X GET https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/contacts(1fa1e5b9-88df-e311-b8e5-6c3be5a8b200) \
  -H "Accept: application/json" \
  -H "OData-MaxVersion: 4.0"  \
  -H "OData-Version: 4.0" \
  -H "Authorization: Bearer DYNAMICS_CRM_ACCESS_TOKEN"

C# Example

Chilkat.Rest rest = new Chilkat.Rest();
bool success;

//  URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/contacts(1fa1e5b9-88df-e311-b8e5-6c3be5a8b200)
bool bTls = true;
int port = 443;
bool bAutoReconnect = true;
success = rest.Connect("my-dynamics-domain.api.crm.dynamics.com",port,bTls,bAutoReconnect);
if (success != true) {
    Debug.WriteLine("ConnectFailReason: " + Convert.ToString(rest.ConnectFailReason));
    Debug.WriteLine(rest.LastErrorText);
    return;
}

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

Chilkat.StringBuilder sbResponseBody = new Chilkat.StringBuilder();
success = rest.FullRequestNoBodySb("GET","/api/data/v9.0/contacts(1fa1e5b9-88df-e311-b8e5-6c3be5a8b200)",sbResponseBody);
if (success != true) {
    Debug.WriteLine(rest.LastErrorText);
    return;
}

int respStatusCode = rest.ResponseStatusCode;
if (respStatusCode >= 400) {
    Debug.WriteLine("Response Status Code = " + Convert.ToString(respStatusCode));
    Debug.WriteLine("Response Header:");
    Debug.WriteLine(rest.ResponseHeader);
    Debug.WriteLine("Response Body:");
    Debug.WriteLine(sbResponseBody.GetAsString());
    return;
}

Chilkat.JsonObject jsonResponse = new Chilkat.JsonObject();
jsonResponse.LoadSb(sbResponseBody);

string odataContext = jsonResponse.StringOf("\"@odata.context\"");
string odataEtag = jsonResponse.StringOf("\"@odata.etag\"");
int customertypecode = jsonResponse.IntOf("customertypecode");
int address1_latitude = jsonResponse.IntOf("address1_latitude");
string birthdate = jsonResponse.StringOf("birthdate");
bool merged = jsonResponse.BoolOf("merged");
int gendercode = jsonResponse.IntOf("gendercode");
int territorycode = jsonResponse.IntOf("territorycode");
string emailaddress1 = jsonResponse.StringOf("emailaddress1");
int haschildrencode = jsonResponse.IntOf("haschildrencode");
int preferredappointmenttimecode = jsonResponse.IntOf("preferredappointmenttimecode");
bool isbackofficecustomer = jsonResponse.BoolOf("isbackofficecustomer");
string modifiedon = jsonResponse.StringOf("modifiedon");
string v_owninguser_value = jsonResponse.StringOf("_owninguser_value");
int importsequencenumber = jsonResponse.IntOf("importsequencenumber");
string address1_composite = jsonResponse.StringOf("address1_composite");
int address1_longitude = jsonResponse.IntOf("address1_longitude");
bool marketingonly = jsonResponse.BoolOf("marketingonly");
bool donotphone = jsonResponse.BoolOf("donotphone");
int preferredcontactmethodcode = jsonResponse.IntOf("preferredcontactmethodcode");
int educationcode = jsonResponse.IntOf("educationcode");
string v_ownerid_value = jsonResponse.StringOf("_ownerid_value");
int customersizecode = jsonResponse.IntOf("customersizecode");
string firstname = jsonResponse.StringOf("firstname");
bool donotpostalmail = jsonResponse.BoolOf("donotpostalmail");
string yomifullname = jsonResponse.StringOf("yomifullname");
int address2_addresstypecode = jsonResponse.IntOf("address2_addresstypecode");
bool donotemail = jsonResponse.BoolOf("donotemail");
int address2_shippingmethodcode = jsonResponse.IntOf("address2_shippingmethodcode");
string fullname = jsonResponse.StringOf("fullname");
int timezoneruleversionnumber = jsonResponse.IntOf("timezoneruleversionnumber");
string address1_addressid = jsonResponse.StringOf("address1_addressid");
int address2_freighttermscode = jsonResponse.IntOf("address2_freighttermscode");
int statuscode = jsonResponse.IntOf("statuscode");
string createdon = jsonResponse.StringOf("createdon");
string address1_stateorprovince = jsonResponse.StringOf("address1_stateorprovince");
string lastname = jsonResponse.StringOf("lastname");
bool donotsendmm = jsonResponse.BoolOf("donotsendmm");
bool donotfax = jsonResponse.BoolOf("donotfax");
int leadsourcecode = jsonResponse.IntOf("leadsourcecode");
string address1_country = jsonResponse.StringOf("address1_country");
int versionnumber = jsonResponse.IntOf("versionnumber");
string address1_line1 = jsonResponse.StringOf("address1_line1");
bool creditonhold = jsonResponse.BoolOf("creditonhold");
string telephone1 = jsonResponse.StringOf("telephone1");
string v_owningbusinessunit_value = jsonResponse.StringOf("_owningbusinessunit_value");
string address3_addressid = jsonResponse.StringOf("address3_addressid");
bool donotbulkemail = jsonResponse.BoolOf("donotbulkemail");
string v_modifiedby_value = jsonResponse.StringOf("_modifiedby_value");
bool followemail = jsonResponse.BoolOf("followemail");
int shippingmethodcode = jsonResponse.IntOf("shippingmethodcode");
string v_createdby_value = jsonResponse.StringOf("_createdby_value");
string address1_city = jsonResponse.StringOf("address1_city");
bool donotbulkpostalmail = jsonResponse.BoolOf("donotbulkpostalmail");
string v_parentcustomerid_value = jsonResponse.StringOf("_parentcustomerid_value");
string contactid = jsonResponse.StringOf("contactid");
bool participatesinworkflow = jsonResponse.BoolOf("participatesinworkflow");
int statecode = jsonResponse.IntOf("statecode");
string overriddencreatedon = jsonResponse.StringOf("overriddencreatedon");
string address2_addressid = jsonResponse.StringOf("address2_addressid");
string address1_postalcode = jsonResponse.StringOf("address1_postalcode");
int int_kloutscore = jsonResponse.IntOf("int_kloutscore");
string spousesname = jsonResponse.StringOf("spousesname");
string emailaddress3 = jsonResponse.StringOf("emailaddress3");
string address3_telephone3 = jsonResponse.StringOf("address3_telephone3");
string mobilephone = jsonResponse.StringOf("mobilephone");
string utcconversiontimezonecode = jsonResponse.StringOf("utcconversiontimezonecode");
string v_preferredserviceid_value = jsonResponse.StringOf("_preferredserviceid_value");
string address3_shippingmethodcode = jsonResponse.StringOf("address3_shippingmethodcode");
string int_twitterservice = jsonResponse.StringOf("int_twitterservice");
string annualincome = jsonResponse.StringOf("annualincome");
string fax = jsonResponse.StringOf("fax");
string telephone3 = jsonResponse.StringOf("telephone3");
string address1_primarycontactname = jsonResponse.StringOf("address1_primarycontactname");
string address3_city = jsonResponse.StringOf("address3_city");
string lastonholdtime = jsonResponse.StringOf("lastonholdtime");
string address2_stateorprovince = jsonResponse.StringOf("address2_stateorprovince");
string address2_line1 = jsonResponse.StringOf("address2_line1");
string assistantphone = jsonResponse.StringOf("assistantphone");
string lastusedincampaign = jsonResponse.StringOf("lastusedincampaign");
string address3_freighttermscode = jsonResponse.StringOf("address3_freighttermscode");
string pager = jsonResponse.StringOf("pager");
string employeeid = jsonResponse.StringOf("employeeid");
string managername = jsonResponse.StringOf("managername");
string address1_name = jsonResponse.StringOf("address1_name");
string department = jsonResponse.StringOf("department");
string address3_country = jsonResponse.StringOf("address3_country");
string address2_telephone1 = jsonResponse.StringOf("address2_telephone1");
string address2_primarycontactname = jsonResponse.StringOf("address2_primarycontactname");
string address2_latitude = jsonResponse.StringOf("address2_latitude");
string address3_latitude = jsonResponse.StringOf("address3_latitude");
string address2_postalcode = jsonResponse.StringOf("address2_postalcode");
string entityimage_timestamp = jsonResponse.StringOf("entityimage_timestamp");
string v_originatingleadid_value = jsonResponse.StringOf("_originatingleadid_value");
string v_masterid_value = jsonResponse.StringOf("_masterid_value");
string v_createdonbehalfby_value = jsonResponse.StringOf("_createdonbehalfby_value");
string address3_postofficebox = jsonResponse.StringOf("address3_postofficebox");
string subscriptionid = jsonResponse.StringOf("subscriptionid");
string business2 = jsonResponse.StringOf("business2");
string address3_county = jsonResponse.StringOf("address3_county");
string address1_telephone2 = jsonResponse.StringOf("address1_telephone2");
string address1_freighttermscode = jsonResponse.StringOf("address1_freighttermscode");
string address3_addresstypecode = jsonResponse.StringOf("address3_addresstypecode");
string address1_addresstypecode = jsonResponse.StringOf("address1_addresstypecode");
string aging90_base = jsonResponse.StringOf("aging90_base");
string address3_primarycontactname = jsonResponse.StringOf("address3_primarycontactname");
string familystatuscode = jsonResponse.StringOf("familystatuscode");
string home2 = jsonResponse.StringOf("home2");
string int_kloutscoreservice = jsonResponse.StringOf("int_kloutscoreservice");
string address2_utcoffset = jsonResponse.StringOf("address2_utcoffset");
string aging60 = jsonResponse.StringOf("aging60");
string telephone2 = jsonResponse.StringOf("telephone2");
string yomimiddlename = jsonResponse.StringOf("yomimiddlename");
string v_modifiedonbehalfby_value = jsonResponse.StringOf("_modifiedonbehalfby_value");
string jobtitle = jsonResponse.StringOf("jobtitle");
string address3_utcoffset = jsonResponse.StringOf("address3_utcoffset");
string address1_telephone3 = jsonResponse.StringOf("address1_telephone3");
string address2_line2 = jsonResponse.StringOf("address2_line2");
string creditlimit_base = jsonResponse.StringOf("creditlimit_base");
string address3_line1 = jsonResponse.StringOf("address3_line1");
string address1_county = jsonResponse.StringOf("address1_county");
string v_createdbyexternalparty_value = jsonResponse.StringOf("_createdbyexternalparty_value");
string entityimageid = jsonResponse.StringOf("entityimageid");
string processid = jsonResponse.StringOf("processid");
string int_facebook = jsonResponse.StringOf("int_facebook");
string description = jsonResponse.StringOf("description");
string address1_fax = jsonResponse.StringOf("address1_fax");
string address3_line2 = jsonResponse.StringOf("address3_line2");
string externaluseridentifier = jsonResponse.StringOf("externaluseridentifier");
string int_facebookservice = jsonResponse.StringOf("int_facebookservice");
string aging30_base = jsonResponse.StringOf("aging30_base");
string v_callback = jsonResponse.StringOf("callback");
string emailaddress2 = jsonResponse.StringOf("emailaddress2");
string address2_line3 = jsonResponse.StringOf("address2_line3");
string managerphone = jsonResponse.StringOf("managerphone");
string websiteurl = jsonResponse.StringOf("websiteurl");
string exchangerate = jsonResponse.StringOf("exchangerate");
string address1_telephone1 = jsonResponse.StringOf("address1_telephone1");
string address3_composite = jsonResponse.StringOf("address3_composite");
string address3_fax = jsonResponse.StringOf("address3_fax");
string childrensnames = jsonResponse.StringOf("childrensnames");
string v_owningteam_value = jsonResponse.StringOf("_owningteam_value");
string numberofchildren = jsonResponse.StringOf("numberofchildren");
string address2_postofficebox = jsonResponse.StringOf("address2_postofficebox");
string aging90 = jsonResponse.StringOf("aging90");
string aging60_base = jsonResponse.StringOf("aging60_base");
string v_transactioncurrencyid_value = jsonResponse.StringOf("_transactioncurrencyid_value");
string entityimage = jsonResponse.StringOf("entityimage");
string v_modifiedbyexternalparty_value = jsonResponse.StringOf("_modifiedbyexternalparty_value");
string paymenttermscode = jsonResponse.StringOf("paymenttermscode");
string address3_name = jsonResponse.StringOf("address3_name");
string ftpsiteurl = jsonResponse.StringOf("ftpsiteurl");
string address1_shippingmethodcode = jsonResponse.StringOf("address1_shippingmethodcode");
string v_preferredsystemuserid_value = jsonResponse.StringOf("_preferredsystemuserid_value");
string address2_telephone2 = jsonResponse.StringOf("address2_telephone2");
string v_slainvokedid_value = jsonResponse.StringOf("_slainvokedid_value");
string address3_telephone1 = jsonResponse.StringOf("address3_telephone1");
string nickname = jsonResponse.StringOf("nickname");
string address1_postofficebox = jsonResponse.StringOf("address1_postofficebox");
string v_preferredequipmentid_value = jsonResponse.StringOf("_preferredequipmentid_value");
string assistantname = jsonResponse.StringOf("assistantname");
string address2_country = jsonResponse.StringOf("address2_country");
string v_accountid_value = jsonResponse.StringOf("_accountid_value");
string address2_name = jsonResponse.StringOf("address2_name");
string stageid = jsonResponse.StringOf("stageid");
string address3_longitude = jsonResponse.StringOf("address3_longitude");
string onholdtime = jsonResponse.StringOf("onholdtime");
string address2_telephone3 = jsonResponse.StringOf("address2_telephone3");
string address3_upszone = jsonResponse.StringOf("address3_upszone");
string aging30 = jsonResponse.StringOf("aging30");
string address2_upszone = jsonResponse.StringOf("address2_upszone");
string address1_upszone = jsonResponse.StringOf("address1_upszone");
string creditlimit = jsonResponse.StringOf("creditlimit");
string salutation = jsonResponse.StringOf("salutation");
string traversedpath = jsonResponse.StringOf("traversedpath");
string accountrolecode = jsonResponse.StringOf("accountrolecode");
string address1_utcoffset = jsonResponse.StringOf("address1_utcoffset");
string governmentid = jsonResponse.StringOf("governmentid");
string annualincome_base = jsonResponse.StringOf("annualincome_base");
string address3_stateorprovince = jsonResponse.StringOf("address3_stateorprovince");
string address3_postalcode = jsonResponse.StringOf("address3_postalcode");
string address2_city = jsonResponse.StringOf("address2_city");
string msdyn_gdproptout = jsonResponse.StringOf("msdyn_gdproptout");
string company = jsonResponse.StringOf("company");
string address1_line2 = jsonResponse.StringOf("address1_line2");
string address2_longitude = jsonResponse.StringOf("address2_longitude");
string int_twitter = jsonResponse.StringOf("int_twitter");
string address3_telephone2 = jsonResponse.StringOf("address3_telephone2");
string yomifirstname = jsonResponse.StringOf("yomifirstname");
string address2_composite = jsonResponse.StringOf("address2_composite");
string address2_county = jsonResponse.StringOf("address2_county");
string suffix = jsonResponse.StringOf("suffix");
string anniversary = jsonResponse.StringOf("anniversary");
string v_parentcontactid_value = jsonResponse.StringOf("_parentcontactid_value");
string address2_fax = jsonResponse.StringOf("address2_fax");
string yomilastname = jsonResponse.StringOf("yomilastname");
string preferredappointmentdaycode = jsonResponse.StringOf("preferredappointmentdaycode");
string entityimage_url = jsonResponse.StringOf("entityimage_url");
string address1_line3 = jsonResponse.StringOf("address1_line3");
string v_defaultpricelevelid_value = jsonResponse.StringOf("_defaultpricelevelid_value");
string v_slaid_value = jsonResponse.StringOf("_slaid_value");
string middlename = jsonResponse.StringOf("middlename");
string address3_line3 = jsonResponse.StringOf("address3_line3");
string timespentbymeonemailandmeetings = jsonResponse.StringOf("timespentbymeonemailandmeetings");

Sample JSON Response Body

{
  "@odata.context": "https://mydomain.api.crm.dynamics.com/api/data/v9.0/$metadata#contacts/$entity",
  "@odata.etag": "W/\"1162210\"",
  "customertypecode": 1,
  "address1_latitude": 35.82096,
  "birthdate": "1965-05-24",
  "merged": false,
  "gendercode": 1,
  "territorycode": 1,
  "emailaddress1": "tom@cohowinery.com",
  "haschildrencode": 1,
  "preferredappointmenttimecode": 1,
  "isbackofficecustomer": false,
  "modifiedon": "2018-03-12T16:09:53Z",
  "_owninguser_value": "55e68414-a277-42d6-ba36-d90484708a1d",
  "importsequencenumber": 104,
  "address1_composite": "4405 Balboa Court\r\nSanta Cruz, NM 72052\r\nUS",
  "address1_longitude": -106.21346,
  "marketingonly": false,
  "donotphone": false,
  "preferredcontactmethodcode": 1,
  "educationcode": 1,
  "_ownerid_value": "55e68414-a277-42d6-ba36-d90484708a1d",
  "customersizecode": 1,
  "firstname": "Tomasz",
  "donotpostalmail": false,
  "yomifullname": "Tomasz Bochenek",
  "address2_addresstypecode": 1,
  "donotemail": false,
  "address2_shippingmethodcode": 1,
  "fullname": "Tomasz Bochenek",
  "timezoneruleversionnumber": 0,
  "address1_addressid": "c3a917d8-1daa-463b-a4ac-f6d9878d7456",
  "address2_freighttermscode": 1,
  "statuscode": 1,
  "createdon": "2017-01-20T22:40:01Z",
  "address1_stateorprovince": "NM",
  "lastname": "Bochenek",
  "donotsendmm": false,
  "donotfax": false,
  "leadsourcecode": 1,
  "address1_country": "US",
  "versionnumber": 1162210,
  "address1_line1": "4405 Balboa Court",
  "creditonhold": false,
  "telephone1": "456-698-4581",
  "_owningbusinessunit_value": "c4106190-c81e-e811-a980-000d3a192e9a",
  "address3_addressid": "e3e5cc17-4990-4d08-8a4d-c16ca45217ab",
  "donotbulkemail": false,
  "_modifiedby_value": "e00ba668-e2de-47bc-8f92-ab9573f92ff4",
  "followemail": true,
  "shippingmethodcode": 1,
  "_createdby_value": "55e68414-a277-42d6-ba36-d90484708a1d",
  "address1_city": "Santa Cruz",
  "donotbulkpostalmail": false,
  "_parentcustomerid_value": "b0a19cdd-88df-e311-b8e5-6c3be5a8b200",
  "contactid": "1fa1e5b9-88df-e311-b8e5-6c3be5a8b200",
  "participatesinworkflow": false,
  "statecode": 0,
  "overriddencreatedon": "2018-03-03T12:22:25Z",
  "address2_addressid": "fee626cd-e834-4a68-a54e-b98c23847b2d",
  "address1_postalcode": "72052",
  "int_kloutscore": 90,
  "spousesname": null,
  "emailaddress3": null,
  "address3_telephone3": null,
  "mobilephone": null,
  "utcconversiontimezonecode": null,
  "_preferredserviceid_value": null,
  "address3_shippingmethodcode": null,
  "int_twitterservice": null,
  "annualincome": null,
  "fax": null,
  "telephone3": null,
  "address1_primarycontactname": null,
  "address3_city": null,
  "lastonholdtime": null,
  "address2_stateorprovince": null,
  "address2_line1": null,
  "assistantphone": null,
  "lastusedincampaign": null,
  "address3_freighttermscode": null,
  "pager": null,
  "employeeid": null,
  "managername": null,
  "address1_name": null,
  "department": null,
  "address3_country": null,
  "address2_telephone1": null,
  "address2_primarycontactname": null,
  "address2_latitude": null,
  "address3_latitude": null,
  "address2_postalcode": null,
  "entityimage_timestamp": null,
  "_originatingleadid_value": null,
  "_masterid_value": null,
  "_createdonbehalfby_value": null,
  "address3_postofficebox": null,
  "subscriptionid": null,
  "business2": null,
  "address3_county": null,
  "address1_telephone2": null,
  "address1_freighttermscode": null,
  "address3_addresstypecode": null,
  "address1_addresstypecode": null,
  "aging90_base": null,
  "address3_primarycontactname": null,
  "familystatuscode": null,
  "home2": null,
  "int_kloutscoreservice": null,
  "address2_utcoffset": null,
  "aging60": null,
  "telephone2": null,
  "yomimiddlename": null,
  "_modifiedonbehalfby_value": null,
  "jobtitle": null,
  "address3_utcoffset": null,
  "address1_telephone3": null,
  "address2_line2": null,
  "creditlimit_base": null,
  "address3_line1": null,
  "address1_county": null,
  "_createdbyexternalparty_value": null,
  "entityimageid": null,
  "processid": null,
  "int_facebook": null,
  "description": null,
  "address1_fax": null,
  "address3_line2": null,
  "externaluseridentifier": null,
  "int_facebookservice": null,
  "aging30_base": null,
  "callback": null,
  "emailaddress2": null,
  "address2_line3": null,
  "managerphone": null,
  "websiteurl": null,
  "exchangerate": null,
  "address1_telephone1": null,
  "address3_composite": null,
  "address3_fax": null,
  "childrensnames": null,
  "_owningteam_value": null,
  "numberofchildren": null,
  "address2_postofficebox": null,
  "aging90": null,
  "aging60_base": null,
  "_transactioncurrencyid_value": null,
  "entityimage": null,
  "_modifiedbyexternalparty_value": null,
  "paymenttermscode": null,
  "address3_name": null,
  "ftpsiteurl": null,
  "address1_shippingmethodcode": null,
  "_preferredsystemuserid_value": null,
  "address2_telephone2": null,
  "_slainvokedid_value": null,
  "address3_telephone1": null,
  "nickname": null,
  "address1_postofficebox": null,
  "_preferredequipmentid_value": null,
  "assistantname": null,
  "address2_country": null,
  "_accountid_value": null,
  "address2_name": null,
  "stageid": null,
  "address3_longitude": null,
  "onholdtime": null,
  "address2_telephone3": null,
  "address3_upszone": null,
  "aging30": null,
  "address2_upszone": null,
  "address1_upszone": null,
  "creditlimit": null,
  "salutation": null,
  "traversedpath": null,
  "accountrolecode": null,
  "address1_utcoffset": null,
  "governmentid": null,
  "annualincome_base": null,
  "address3_stateorprovince": null,
  "address3_postalcode": null,
  "address2_city": null,
  "msdyn_gdproptout": null,
  "company": null,
  "address1_line2": null,
  "address2_longitude": null,
  "int_twitter": null,
  "address3_telephone2": null,
  "yomifirstname": null,
  "address2_composite": null,
  "address2_county": null,
  "suffix": null,
  "anniversary": null,
  "_parentcontactid_value": null,
  "address2_fax": null,
  "yomilastname": null,
  "preferredappointmentdaycode": null,
  "entityimage_url": null,
  "address1_line3": null,
  "_defaultpricelevelid_value": null,
  "_slaid_value": null,
  "middlename": null,
  "address3_line3": null,
  "timespentbymeonemailandmeetings": null
}