C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Dynamics 365 Web API Enhancement - Part Two
WhatsApp
Mahender Pal
8y
9.7k
0
0
100
Article
Before reading this article, please go through the articles given below.
Dynamics 365 Web API Enhancement
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.
api / data / v8 .2 / EntityDefinitions(LogicalName =
'lead'
)
The complete request for query lead entity metadata is shown below.
var
serverURL = Xrm.Page.context.getClientUrl();
var
req =
new
XMLHttpRequest();
req.open(
"GET"
, serverURL +
"/api/data/v8.2/EntityDefinitions(LogicalName='lead')"
,
true
);
req.setRequestHeader(
"Accept"
,
"application/json"
);
req.setRequestHeader(
"Content-Type"
,
"application/json; charset=utf-8"
);
req.setRequestHeader(
"OData-MaxVersion"
,
"4.0"
);
req.setRequestHeader(
"OData-Version"
,
"4.0"
);
req.onreadystatechange =
function
() {
if
(
this
.readyState == 4
/* complete */
) {
req.onreadystatechange =
null
;
if
(
this
.status == 200) {
var
data = JSON.parse(
this
.response);
//process metadata
}
else
{
var
error = JSON.parse(
this
.response).error;
alert(error.message);
}
}
};
req.send();
It will
return
lead entity metadata like following
If we want to return all the entity metadata, we can use our request, as shown below.
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.
api / data / v8 .2 / EntityDefinitions(LogicalName =
'lead'
) / Attributes
If want to retrieve only specific attribute, we can use the request, as shown below.
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.
api / data / v8 .2 / RelationshipDefinitions(SchemaName =
'account_originating_lead'
)
Stay tuned for more Dynamics 365 features updates.
Dynamics 365
Dynamics CRM
Web API
Up Next
Ebook Download
View all
Printing in C# Made Easy
Read by 22.5k people
Download Now!
Learn
View all
HIMBAP
We are expert in Microsoft Power Platform.
Membership not found