{"id":1588,"date":"2012-05-16T21:40:18","date_gmt":"2012-05-16T20:40:18","guid":{"rendered":"http:\/\/thekua.com\/atwork\/?p=1588"},"modified":"2012-05-16T21:40:18","modified_gmt":"2012-05-16T20:40:18","slug":"updating-a-dynamics-crm-customer-record-via-http","status":"publish","type":"post","link":"https:\/\/thekua.com\/atwork\/2012\/05\/updating-a-dynamics-crm-customer-record-via-http\/","title":{"rendered":"Updating a Dynamics CRM Customer Record via HTTP"},"content":{"rendered":"<p>My current project integrates with the <a href=\"http:\/\/www.microsoft.com\/en-gb\/dynamics\/default.aspx\" title=\"Dynamics\">Microsoft Dynamics CRM system<\/a> for managing customer records. We already spiked out authenticating and our next step was attempting to update a record via its &#8220;<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/gg334279.aspx\" title=\"Dynamics CRM REST Endpoint\">REST Endpoint<\/a>&#8220;. <\/p>\n<p>On retrieving a record, you follow the <a href=\"http:\/\/www.odata.org\">OData<\/a> style for finding something of relevant. Updating a record is interesting as we only want to send the fields that need to change remotely. Looking at their <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/gg309549.aspx\" title=\"Sample Update Code\">sample code<\/a>, you need to:<\/p>\n<ul>\n<li>Create an authenticated POST request<\/li>\n<li>Set the <code>X-HTTP-Method<\/code> to <code>MERGE<\/code><\/li>\n<li>Set the appropriate content type for the content you intend on sending. In our case, set the header <code>Accept<\/code> to <code>application\/json<\/code> and the <code>Content-Type<\/code> to <code>application\/json; charset=utf-8<\/code><\/li>\n<\/ul>\n<p>Our end point for a contact looked something like:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">https:\/\/crm.thekua.com\/xrmservices\/2011\/organizationdata.svc\/ContactSet(guid'867dc3f2-909e-e111-9912-0050569c2d72')<\/pre>\n<p>.<\/p>\n<p>Updating simple fields off a contact is easy. We post something like: <\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">{\r\n  &quot;EMailAddress1&quot;:&quot;spike.jones4@gmail.com&quot;,\r\n  &quot;MobilePhone&quot;:&quot;33335&quot;\r\n}<\/pre>\n<p>We receive a HTTP 204 (No Content) on a success. Posting an invalid attribute (i.e. one that does not exist on the ContactSet such as &#8220;EMailAddreXXXs1&#8221;) results in a HTTP 400 (Bad request) and a nice description about what&#8217;s wrong. You will also get a HTTP 400 if you post the wrong datatype such as sending a string where they expect a number. If you pass invalid values (but of the correct datatype) for a field, your response is a HTTP 500 with a message like <code>The value of 'gendercode' on record of type 'contact' is outside the valid range.\"<\/code><\/p>\n<p><strong>Updating Option Set Values<\/strong><\/p>\n<p>Updating simple datatypes is easy and obvious from a JSON point of view. You have a couple of complex datatypes, such as the standard <code>GenderCode<\/code>. When you query for a record, you get back something that looks like <\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">{&quot;GenderCode&quot;=&gt;{&quot;__metadata&quot;=&gt;{&quot;type&quot;=&gt;&quot;Microsoft.Crm.Sdk.Data.Services.OptionSetValue&quot;}, &quot;Value&quot;=&gt;1}}<\/pre>\n<p>To update something like this, you need to send a nested JSON object. The example follows <\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">{\r\n  &quot;EMailAddress1&quot;:&quot;spike.jones4@gmail.com&quot;,\r\n  &quot;MobilePhone&quot;:&quot;33335&quot;,\r\n  &quot;GenderCode&quot;: { \r\n    &quot;Value&quot; : &quot;1&quot;\r\n  }\r\n}<\/pre>\n<p>A HTTP 204 (No Content) response indicates a success. Viola! <\/p>\n","protected":false},"excerpt":{"rendered":"<p>My current project integrates with the Microsoft Dynamics CRM system for managing customer records. We already spiked out authenticating and our next step was attempting to update a record via its &#8220;REST Endpoint&#8220;. On retrieving a record, you follow the OData style for finding something of relevant. Updating a record is interesting as we only [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[57,4],"tags":[],"class_list":["post-1588","post","type-post","status-publish","format-standard","hentry","category-crm","category-development","post-preview"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Updating a Dynamics CRM Customer Record via HTTP - patkua@work<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/thekua.com\/atwork\/2012\/05\/updating-a-dynamics-crm-customer-record-via-http\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Updating a Dynamics CRM Customer Record via HTTP - patkua@work\" \/>\n<meta property=\"og:description\" content=\"My current project integrates with the Microsoft Dynamics CRM system for managing customer records. We already spiked out authenticating and our next step was attempting to update a record via its &#8220;REST Endpoint&#8220;. On retrieving a record, you follow the OData style for finding something of relevant. Updating a record is interesting as we only [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/thekua.com\/atwork\/2012\/05\/updating-a-dynamics-crm-customer-record-via-http\/\" \/>\n<meta property=\"og:site_name\" content=\"patkua@work\" \/>\n<meta property=\"article:published_time\" content=\"2012-05-16T20:40:18+00:00\" \/>\n<meta name=\"author\" content=\"Patrick\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@patkua\" \/>\n<meta name=\"twitter:site\" content=\"@patkua\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Patrick\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2012\\\/05\\\/updating-a-dynamics-crm-customer-record-via-http\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2012\\\/05\\\/updating-a-dynamics-crm-customer-record-via-http\\\/\"},\"author\":{\"name\":\"Patrick\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#\\\/schema\\\/person\\\/c942203c9ed3ff9e21c6c49a996ea3ae\"},\"headline\":\"Updating a Dynamics CRM Customer Record via HTTP\",\"datePublished\":\"2012-05-16T20:40:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2012\\\/05\\\/updating-a-dynamics-crm-customer-record-via-http\\\/\"},\"wordCount\":367,\"commentCount\":1,\"articleSection\":[\"CRM\",\"Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/thekua.com\\\/atwork\\\/2012\\\/05\\\/updating-a-dynamics-crm-customer-record-via-http\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2012\\\/05\\\/updating-a-dynamics-crm-customer-record-via-http\\\/\",\"url\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2012\\\/05\\\/updating-a-dynamics-crm-customer-record-via-http\\\/\",\"name\":\"Updating a Dynamics CRM Customer Record via HTTP - patkua@work\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#website\"},\"datePublished\":\"2012-05-16T20:40:18+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#\\\/schema\\\/person\\\/c942203c9ed3ff9e21c6c49a996ea3ae\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2012\\\/05\\\/updating-a-dynamics-crm-customer-record-via-http\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/thekua.com\\\/atwork\\\/2012\\\/05\\\/updating-a-dynamics-crm-customer-record-via-http\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2012\\\/05\\\/updating-a-dynamics-crm-customer-record-via-http\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Updating a Dynamics CRM Customer Record via HTTP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#website\",\"url\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/\",\"name\":\"patkua@work\",\"description\":\"The intersection of technology and leadership\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#\\\/schema\\\/person\\\/c942203c9ed3ff9e21c6c49a996ea3ae\",\"name\":\"Patrick\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g\",\"caption\":\"Patrick\"},\"sameAs\":[\"http:\\\/\\\/thekua.com\\\/atwork\"],\"url\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/author\\\/patrick\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Updating a Dynamics CRM Customer Record via HTTP - patkua@work","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/thekua.com\/atwork\/2012\/05\/updating-a-dynamics-crm-customer-record-via-http\/","og_locale":"en_US","og_type":"article","og_title":"Updating a Dynamics CRM Customer Record via HTTP - patkua@work","og_description":"My current project integrates with the Microsoft Dynamics CRM system for managing customer records. We already spiked out authenticating and our next step was attempting to update a record via its &#8220;REST Endpoint&#8220;. On retrieving a record, you follow the OData style for finding something of relevant. Updating a record is interesting as we only [&hellip;]","og_url":"https:\/\/thekua.com\/atwork\/2012\/05\/updating-a-dynamics-crm-customer-record-via-http\/","og_site_name":"patkua@work","article_published_time":"2012-05-16T20:40:18+00:00","author":"Patrick","twitter_card":"summary_large_image","twitter_creator":"@patkua","twitter_site":"@patkua","twitter_misc":{"Written by":"Patrick","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/thekua.com\/atwork\/2012\/05\/updating-a-dynamics-crm-customer-record-via-http\/#article","isPartOf":{"@id":"https:\/\/thekua.com\/atwork\/2012\/05\/updating-a-dynamics-crm-customer-record-via-http\/"},"author":{"name":"Patrick","@id":"https:\/\/thekua.com\/atwork\/#\/schema\/person\/c942203c9ed3ff9e21c6c49a996ea3ae"},"headline":"Updating a Dynamics CRM Customer Record via HTTP","datePublished":"2012-05-16T20:40:18+00:00","mainEntityOfPage":{"@id":"https:\/\/thekua.com\/atwork\/2012\/05\/updating-a-dynamics-crm-customer-record-via-http\/"},"wordCount":367,"commentCount":1,"articleSection":["CRM","Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/thekua.com\/atwork\/2012\/05\/updating-a-dynamics-crm-customer-record-via-http\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/thekua.com\/atwork\/2012\/05\/updating-a-dynamics-crm-customer-record-via-http\/","url":"https:\/\/thekua.com\/atwork\/2012\/05\/updating-a-dynamics-crm-customer-record-via-http\/","name":"Updating a Dynamics CRM Customer Record via HTTP - patkua@work","isPartOf":{"@id":"https:\/\/thekua.com\/atwork\/#website"},"datePublished":"2012-05-16T20:40:18+00:00","author":{"@id":"https:\/\/thekua.com\/atwork\/#\/schema\/person\/c942203c9ed3ff9e21c6c49a996ea3ae"},"breadcrumb":{"@id":"https:\/\/thekua.com\/atwork\/2012\/05\/updating-a-dynamics-crm-customer-record-via-http\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/thekua.com\/atwork\/2012\/05\/updating-a-dynamics-crm-customer-record-via-http\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/thekua.com\/atwork\/2012\/05\/updating-a-dynamics-crm-customer-record-via-http\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/thekua.com\/atwork\/"},{"@type":"ListItem","position":2,"name":"Updating a Dynamics CRM Customer Record via HTTP"}]},{"@type":"WebSite","@id":"https:\/\/thekua.com\/atwork\/#website","url":"https:\/\/thekua.com\/atwork\/","name":"patkua@work","description":"The intersection of technology and leadership","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/thekua.com\/atwork\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/thekua.com\/atwork\/#\/schema\/person\/c942203c9ed3ff9e21c6c49a996ea3ae","name":"Patrick","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g","caption":"Patrick"},"sameAs":["http:\/\/thekua.com\/atwork"],"url":"https:\/\/thekua.com\/atwork\/author\/patrick\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/posts\/1588","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/comments?post=1588"}],"version-history":[{"count":4,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/posts\/1588\/revisions"}],"predecessor-version":[{"id":1593,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/posts\/1588\/revisions\/1593"}],"wp:attachment":[{"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/media?parent=1588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/categories?post=1588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/tags?post=1588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}