The Microsoft Dynamics 365 Web API is a RESTful web service that expands developers’ ability to interact with Dynamics 365 functionality and data using the HTTP protocol. You can access the endpoints and operations using standard GET, POST, PUT, and DELETE HTTP methods. The Web API uses the Open Data Protocol (ODAP), an OASIS standard that outlines how to build and consume RESTful APIs.
You can access the Microsoft Dynamics API using the Microsoft Visual Studio C# language or client-side JavaScript. To work with C#, developers will need a copy of the IDE Visual Studio 2015 or a more recent version.
For businesses leveraging Microsoft Dynamics 365 for customer relationship management (CRM) and enterprise resource planning (ERP), the Dynamics 365 API provides seamless access to crucial business data. This API enables developers to build custom integrations, automate workflows, and enhance the functionality of their CRM and ERP systems.
You can find free versions of the tool at the Visual Studio Community site. In addition, you must have an established connection to an on-premises or online version of Microsoft Dynamics 365 and a Microsoft Dynamics 365 Server user account.
Developers must authenticate against the Dynamics 365 server before accessing the resources. There are different authentication methods available depending on your development type involving multiple programmatic steps.
Here, you can find an example of a simple project that walks you through setting up a Microsoft Dynamics 365 Web API project in Visual Studio. You can find more detailed instructions here if you prefer working with client-side JavaScript.
The Dynamics 365 API plays a vital role in business operations by allowing applications to interact programmatically with Microsoft Dynamics 365. This means businesses can automate critical tasks, retrieve customer data, and integrate external applications seamlessly. Whether you are working with the D365 API to extract reports, the Dynamics CRM API to manage customer interactions, or the Business Central API to connect financial and operational data, the API structure ensures flexibility and efficiency.
Some key benefits of using the Microsoft Dynamics 365 API include:
Below is an overview of operations you can perform with the Microsoft Dynamics API.
Interactions with the Dynamics Web API occur through HTTP Requests. You must set the appropriate headers and have a way to handle errors that might happen in the response. Start by composing a URL containing the following components:
You can use any of the following methods with your HTTP request:
Web API requests should use the Accept header value application/json. Remember that all errors get returned in JSON format. It’s also a best practice to include the specific OData version and Maximum version used in your code.
Accept: application/json OData-MaxVersion: 4.0 OData-Version: 4.0
All JSONData requests in the body should include a Content-Type header with the value application/json.
Content-Type: application/json
Every successful or failed HTTP response will provide a status code. Below are some common examples.
Below are examples of a request and a response designed to retrieve the name property from three accounts held in Dynamics 365.
GET [Organization URI]/api/data/v8.2/accounts?$select=name&$top=3 HTTP/1.1
Accept: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
{
"@odata.context": "[Organization URI]/api/data/v8.2/$metadata#accounts(name)",
"value": [
{
"@odata.etag": "W/\"502000\"",
"name": "Second Coffee (sample)",
"accountid": "89390c24-9c72-e511-80d4-00155d2a68d1"
},
{
"@odata.etag": "W/\"502001\"",
"name": "Writeware, Inc. (sample)",
"accountid": "8b390c24-9c72-e511-80d4-00155d2a68d1"
},
{
"@odata.etag": "W/\"502002\"",
"name": "New Adventures (sample)",
"accountid": "8d390c24-9c72-e511-80d4-00155d2a68d1"
}
]
}
Dynamics Web API will return a maximum of 5,000 entries per request unless you specify a smaller size. If there are more entries available, you’ll see the @odata.nextLink property returned with the additional results. You will need to issue a new GET request using that property to see the next page of data.
You can specify how many pages you want returned using the following example:
GET [Organization URI]/api/data/v8.2/accounts?$select=name HTTP/1.1
Accept: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
Prefer: odata.maxpagesize=3
HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Content-Length: 402
Preference-Applied: odata.maxpagesize=3
{
"@odata.context": "[Organization URI]/api/data/v8.2/$metadata#accounts(name)",
"value": [
{
"@odata.etag": "W/\"401001\"",
"name": "Second Coffee (sample)",
"accountid": "7d51925c-cde2-e411-80db-00155d2a68cb"
},
{
"@odata.etag": "W/\"401002\"",
"name": "New Software Company, Inc. (sample)",
"accountid": "7f51925c-cde2-e411-80db-00155d2a68cb"
},
{
"@odata.etag": "W/\"401003\"",
"name": "Exciting Company (sample)",
"accountid": "8151925c-cde2-e411-80db-00155d2a68cb"
}
],
"@odata.nextLink": "[Organization URI]/api/data/v8.2/accounts?$select=name&$skiptoken=%3Ccookie%20pagenumber=%222%22%20pagingcookie=%22%253ccookie%2520page%253d%25221%2522%253e%253caccountid%2520last%253d%2522%257b8151925C-CDE2-E411-80DB-00155D2A68CB%257d%2522%2520first%253d%2522%257b7D51925C-CDE2-E411-80DB-00155D2A68CB%257d%2522%2520%252f%253e%253c%252fcookie%253e%22%20/%3E"
}
Below is an example of using a POST request to create a new account entry into Dynamics Web API. You must identify the correct property names and types. Look here for more information.
POST [Organization URI]/api/data/v8.2/accounts HTTP/1.1
Content-Type: application/json; charset=utf-8
OData-MaxVersion: 4.0
OData-Version: 4.0
Accept: application/json
{
"name": "New Web Account",
"creditonhold": false,
"address1_latitude": 58.639583,
"description": "Describes the new sample account",
"revenue": 10000000,
"accountcategorycode": 3
}
HTTP/1.1 204 No Content
OData-Version: 4.0
OData-EntityId: [Organization URI]/api/data/v8.2/accounts(7eb682f1-ca75-e511-80d4-00155d2a68d1)
You can issue a request that returns a status code of 201 for confirmation that the new entity exists in Microsoft Dynamics 365.
POST [Organization URI]/api/data/v8.2/accounts?$select=name,creditonhold,address1_latitude,description,revenue,accountcategorycode,createdon HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Accept: application/json
Content-Type: application/json; charset=utf-8
Prefer: return=representation
{
"name": "New Sample Account",
"creditonhold": false,
"address1_latitude": 55.639583,
"description": "Describes the new account that will return a 201 code",
"revenue": 15000000,
"accountcategorycode": 2
}
HTTP/1.1 201 Created
Content-Type: application/json; odata.metadata=minimal
Preference-Applied: return=representation
OData-Version: 4.0
{
"@odata.context": "[Organization URI]/api/data/v8.2/$metadata#accounts/$entity",
"@odata.etag": "W/\"536530\"",
"accountid": "d6f193fc-ce85-e611-80d8-00155d2a68de",
"accountcategorycode": 2,
"description": "This describes the newly created sample account that returns a 201 status",
"address1_latitude": 55.63958,
"creditonhold": false,
"name": "New Sample Account",
"createdon": "2016-09-28T22:57:53Z",
"revenue": 15000000.0000,
"_transactioncurrencyid_value": "048dddaa-6f7f-e611-80d3-00155db5e0b6"
}
The Microsoft Dynamics API expands your ability to connect with Dynamics 365 from various applications. Internet eBusiness Solutions can guide you in integrating the platform with other business applications. Contact one of our representatives if you want to expand your use of Dynamics 365.