Starting Microsoft Dynamics CRM API (JavaScript)

You can enhance Microsoft Dynamics CRM user-experiences by accessing their API. In this example, JavaScript was used to access the API.

Login

After logging in your instance, on the Ribbon, click Settings and then click Customizations.

Click the Customizations button in the Ribbon.

In the Customizations page, click Developer Resources.

Click the Developer Resource link.

Once you are in the Developer Resources page, look for a section called Instance Web API.

Developer Resources page.

Sample URL

With the Instance Web API, you can call a certain entity type, for example:

Case Entity

https://instance-name.dynamics.com/api/data/v9.1/incidents

Task Entity

https://instance-name.dynamics.com/api/data/v9.1/tasks

Annotations/Notes Entity

https://instance-name.dynamics.com/api/data/v9.1/annotations

View all other entities

https://instance-name.dynamics.com/api/data/v9.1/

The API returns the list of entities.

Sample JavaScript Source Code

You can place the JavaScript in the Web Resource file or use the browser debugger (you must be in CRM and on your keyboard, press F12).

var get_client_url = parent.Xrm.Page.context.getClientUrl();
var req = new XMLHttpRequest();
req.open("GET", get_client_url + "/api/data/v9.1/tasks", false);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.send();
var result = JSON.parse(req.responseText);

Reference

​Microsoft. (2019, March 21). Web API Reference. Retrieved from Microsoft Docs: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/about?view=dynamics-ce-odata-9 

Leave a Reply