Dynamics 365 Web API Enhancement - Part Two

Before reading this article, please go through the articles given below.
In our last article, we discussed new enhancements in Web API to create and update requests. In this article, we are going to discuss enhancements released to query metadata. Web API has made it really simple to query your entity metadata now. If we need to query any entity metadata, we can just specify entity logical name in our Web API to get the request, as shown below.
  1. api / data / v8 .2 / EntityDefinitions(LogicalName = 'lead')  
The complete request for query lead entity metadata is shown below.
  1. var serverURL = Xrm.Page.context.getClientUrl();  
  2. var req = new XMLHttpRequest();  
  3. req.open("GET", serverURL + "/api/data/v8.2/EntityDefinitions(LogicalName='lead')"true);  
  4. req.setRequestHeader("Accept""application/json");  
  5. req.setRequestHeader("Content-Type""application/json; charset=utf-8");  
  6. req.setRequestHeader("OData-MaxVersion""4.0");  
  7. req.setRequestHeader("OData-Version""4.0");  
  8. req.onreadystatechange = function() {  
  9.     if (this.readyState == 4 /* complete */ ) {  
  10.         req.onreadystatechange = null;  
  11.         if (this.status == 200) {  
  12.             var data = JSON.parse(this.response); //process metadata   
  13.         } else {  
  14.             var error = JSON.parse(this.response).error;  
  15.             alert(error.message);  
  16.         }  
  17.     }  
  18. };  
  19. req.send();  
  20. It will  
  21. return lead entity metadata like following  
metadata

If we want to return all the entity metadata, we can use our request, as shown below.
  1. api / data / v8 .2 / EntityDefinitions  
We can also use other variations while querying metadata. For example, if we want to get all the attribute metadata of lead entity, we can use, as shown below.
  1. api / data / v8 .2 / EntityDefinitions(LogicalName = 'lead') / Attributes  
If want to retrieve only specific attribute, we can use the request, as shown below.
  1. api / data / v8 .2 / EntityDefinitions(LogicalName = 'lead') / Attributes(LogicalName = 'address1_city')  
We can also query global option set metadata, using the request mentioned below. 

We will get response, as shownbelow.



Similarly, we can also query relationships, as shown below.
  1. api / data / v8 .2 / RelationshipDefinitions(SchemaName = 'account_originating_lead')  
Stay tuned for more Dynamics 365 features updates.


Similar Articles
HIMBAP
We are expert in Microsoft Power Platform.