{Dynamics CRM/ 365 + Web API} New Metadata Query features in Web API in Dynamics 365

Dynamics 365 is in and just like me, CRM enthusiasts all over the world are simply WOW’ed by its wonderful offerings. After all, this has been a giant leap by Microsoft and indeed a great opportunity for all consultants to me to plunge into unknown territories and conquer it.

In this blog post, I will walk you through the new Metadata Query features that has been introduced with Dynamics 365 Web API. Off late I have been developing some tools using were using the WEB API endpoint and these new additions to the WEB API will really help developers to query the metadata in a very simple way. So without wasting more time, let me straight way give you a flavor of this.

With Dynamics 365, the Web API endpoint has been upgraded to v8.2. So it would be typically in this format – image

Now comes the interesting part which is querying the metadata.

Below are some of the scenarios I explored and it works like a charm. I will show all the examples here related to the “contact” entity for my organization. The best thing that you find in the below examples is, using the Web API you can query the same way you do in organization service for your CRM Metadata.

Query Entity Metadata

https://xrmtr30.api.crm.dynamics.com/api/data/v8.2/EntityDefinitions(LogicalName=’contact’)

Isn’t it great! You can query the entity metadata using the EntityLogicalName just like you do in Organization Service.

And below is the JSON result I get which you just need to parse to get your data back.

image

Query Entity Metadata along with all attributes

https://xrmtr30.api.crm.dynamics.com/api/data/v8.2/EntityDefinitions(LogicalName=’contact’)/Attributes

And below is the sample JSON response for the field ‘First Name’

image

Querying single Field Metadata

So how about you want to query just a single field metadata. Well dynamics 365 is not here to disappoint you Smile

In the below query, I have just queried for the firstname metadata for the contact entity.

https://xrmtr30.api.crm.dynamics.com/api/data/v8.2/EntityDefinitions(LogicalName=’contact’)/Attributes(LogicalName=’firstname’)

And below is the JSON response.

image

Querying global Optionsets

Enough of querying fields specific to entity. How about global optionset? And yet again Dynamics 365 has your back.

https://xrmtr30.api.crm.dynamics.com/api/data/v8.2/GlobalOptionSetDefinitions(Name=’decisionmaker’)

In the above example, I am querying for the metadata of a global optionset called ‘decisionmaker’. And below is the sample JSON response.

image

Querying Relationships

The below query will query for the N:N relationship between contact and leads

https://xrmtr30.api.crm.dynamics.com/api/data/v8.2/RelationshipDefinitions(SchemaName=’contactleads_association’)

And below is the JSON response for the same

image

I am still exploring the wonderful features of Dynamics 365 and stay tuned for another interesting update.

Debajit Dutta

(Visit http://www.xrmforyou.com/products.html and checkout our tools library)

1 thought on “{Dynamics CRM/ 365 + Web API} New Metadata Query features in Web API in Dynamics 365”

Comments are closed.