WEB API- Part 2: Retrieve Single Record Using WEB API

Retrieve Single Record Using WEB API

Following  code shows how to fetch an account record using  Guid

var req = new XMLHttpRequest();

var AcccountID="257bAC5D5240-8B31-E611-80E4-5065F38B4681";
req.open("GET", Xrm.Page.context.getClientUrl() +"/api/data/v8.0/accounts(AcccountID)?$select=name", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var name = result["name"];
else {

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s