{"id":2569,"date":"2016-11-12T17:52:44","date_gmt":"2016-11-12T17:52:44","guid":{"rendered":"http:\/\/himbap.com\/blog\/?p=2569"},"modified":"2016-11-12T17:54:31","modified_gmt":"2016-11-12T17:54:31","slug":"dynamics-365-web-api-enhancement-part-2","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=2569","title":{"rendered":"Dynamics 365 Web API enhancement Part 2"},"content":{"rendered":"<p>In our <a href=\"https:\/\/himbap.com\/blog\/?p=2557\">last article <\/a>we discussed new enhancement in Web API for create and update request. In this article we are going to discuss enhancement released to query metadata. Web API made it really simple to query your entity metadata now. If we need to query any entity metadata we can just specific entity logical name in our Web API get request like following:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\napi\/data\/v8.2\/EntityDefinitions(LogicalName='lead')\r\n<\/pre>\n<p>Here is the complete request for query lead entity metadata:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar serverURL = Xrm.Page.context.getClientUrl();\r\n    var req = new XMLHttpRequest();\r\n    req.open(&quot;GET&quot;, serverURL + &quot;\/api\/data\/v8.2\/EntityDefinitions(LogicalName='lead')&quot;, true);\r\n    req.setRequestHeader(&quot;Accept&quot;, &quot;application\/json&quot;);\r\n    req.setRequestHeader(&quot;Content-Type&quot;, &quot;application\/json; charset=utf-8&quot;);\r\n    req.setRequestHeader(&quot;OData-MaxVersion&quot;, &quot;4.0&quot;);\r\n    req.setRequestHeader(&quot;OData-Version&quot;, &quot;4.0&quot;);\r\n    req.onreadystatechange = function() {\r\n        if (this.readyState == 4 \/* complete *\/ ) {\r\n            req.onreadystatechange = null;\r\n            if (this.status == 200) {\r\n                var data = JSON.parse(this.response);\r\n                \/\/process metadata\r\n            } else {\r\n                var error = JSON.parse(this.response).error;\r\n                alert(error.message);\r\n            }\r\n        }\r\n    };\r\n    req.send();\r\n<\/pre>\n<p>It will return lead entity metadata like following:<\/p>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2016\/11\/leadapi.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-2572 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2016\/11\/leadapi-300x277.png\" alt=\"leadapi\" width=\"300\" height=\"277\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2016\/11\/leadapi-300x277.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2016\/11\/leadapi.png 580w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>If we want to return all the entity metadata we can use our request like following:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\napi\/data\/v8.2\/EntityDefinitions\r\n<\/pre>\n<p>We can also use other variations while querying metadata for example if we want to get all attributes metadata of lead entity, we can use like following<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\napi\/data\/v8.2\/EntityDefinitions(LogicalName='lead')\/Attributes\r\n<\/pre>\n<p>And if want to retrieve only specific attribute, we can use following request:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\napi\/data\/v8.2\/EntityDefinitions(LogicalName='lead')\/Attributes(LogicalName='address1_city')\r\n<\/pre>\n<p>We can also query global option set metadata using following request:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\napi\/data\/v8.2\/GlobalOptionSetDefinitions(Name='incident_caseorigincode')\r\n<\/pre>\n<p>and we will get response like following:<\/p>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2016\/11\/optionsetapi.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-2573 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2016\/11\/optionsetapi-300x206.png\" alt=\"optionsetapi\" width=\"300\" height=\"206\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2016\/11\/optionsetapi-300x206.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2016\/11\/optionsetapi-624x429.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2016\/11\/optionsetapi.png 679w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Similarly we can also query relationship using:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\napi\/data\/v8.2\/RelationshipDefinitions(SchemaName='account_originating_lead')\r\n<\/pre>\n<p>Stay tuned for more Dynamics 365 features !!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our last article we discussed new enhancement in Web API for create and update request. In this article we are going to discuss enhancement released to query metadata. Web API made it really simple to query your entity metadata now. If we need to query any entity metadata we can just specific entity logical name in our Web API&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=2569\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[21,402,296],"tags":[416,417,412],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2569"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2569"}],"version-history":[{"count":12,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2569\/revisions"}],"predecessor-version":[{"id":2590,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2569\/revisions\/2590"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2569"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2569"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2569"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}