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

Java Example

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    CkRest rest = new CkRest();
    boolean success;

    //  URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/contacts(1fa1e5b9-88df-e311-b8e5-6c3be5a8b200)
    boolean bTls = true;
    int port = 443;
    boolean bAutoReconnect = true;
    success = rest.Connect("my-dynamics-domain.api.crm.dynamics.com",port,bTls,bAutoReconnect);
    if (success != true) {
        System.out.println("ConnectFailReason: " + rest.get_ConnectFailReason());
        System.out.println(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");

    CkStringBuilder sbResponseBody = new CkStringBuilder();
    success = rest.FullRequestNoBodySb("GET","/api/data/v9.0/contacts(1fa1e5b9-88df-e311-b8e5-6c3be5a8b200)",sbResponseBody);
    if (success != true) {
        System.out.println(rest.lastErrorText());
        return;
        }

    int respStatusCode = rest.get_ResponseStatusCode();
    if (respStatusCode >= 400) {
        System.out.println("Response Status Code = " + respStatusCode);
        System.out.println("Response Header:");
        System.out.println(rest.responseHeader());
        System.out.println("Response Body:");
        System.out.println(sbResponseBody.getAsString());
        return;
        }

    CkJsonObject jsonResponse = new CkJsonObject();
    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");
    boolean 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");
    boolean 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");
    boolean marketingonly = jsonResponse.BoolOf("marketingonly");
    boolean 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");
    boolean donotpostalmail = jsonResponse.BoolOf("donotpostalmail");
    String yomifullname = jsonResponse.stringOf("yomifullname");
    int address2_addresstypecode = jsonResponse.IntOf("address2_addresstypecode");
    boolean 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");
    boolean donotsendmm = jsonResponse.BoolOf("donotsendmm");
    boolean 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");
    boolean creditonhold = jsonResponse.BoolOf("creditonhold");
    String telephone1 = jsonResponse.stringOf("telephone1");
    String v_owningbusinessunit_value = jsonResponse.stringOf("_owningbusinessunit_value");
    String address3_addressid = jsonResponse.stringOf("address3_addressid");
    boolean donotbulkemail = jsonResponse.BoolOf("donotbulkemail");
    String v_modifiedby_value = jsonResponse.stringOf("_modifiedby_value");
    boolean followemail = jsonResponse.BoolOf("followemail");
    int shippingmethodcode = jsonResponse.IntOf("shippingmethodcode");
    String v_createdby_value = jsonResponse.stringOf("_createdby_value");
    String address1_city = jsonResponse.stringOf("address1_city");
    boolean donotbulkpostalmail = jsonResponse.BoolOf("donotbulkpostalmail");
    String v_parentcustomerid_value = jsonResponse.stringOf("_parentcustomerid_value");
    String contactid = jsonResponse.stringOf("contactid");
    boolean 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
}