Dynamics CRM Web API: Streamlining Your Customer Relationship Management
Introduction to Dynamics CRM Web API
Dynamics CRM is a customer relationship management (CRM) software application, and Dynamics CRM Web API is a tool to build business solutions that interact with the application. Microsoft introduced the Web API feature in Dynamics CRM 2016. It allows developers to work with dynamic CRM data in the form of an HTTP request and provides endpoints for data manipulation.
The Web API feature exposes Dynamics CRM data through a JSON (JavaScript Object Notation) protocol, which is an open standard for data exchange. JSON is a lightweight and efficient data format that can be used by any programming language. This makes it easy for developers to integrate Dynamics CRM data into their applications, regardless of the programming language they are using.
The Web API feature is a REST (Representational State Transfer) API, which means it uses HTTP methods to retrieve, create, update, and delete data. REST APIs are widely used in modern web applications as they offer a stateless communication between the client and the server. This means that each request sent by the client includes all the information the server needs to handle the request, which improves performance and scalability.
The Dynamics CRM Web API feature has several benefits, including:
1. Simplified development
The Web API feature simplifies the development of Dynamics CRM solutions by providing a standard interface for data manipulation. Developers can use any programming language that supports HTTP requests and JSON to interact with the application. This allows them to work with familiar tools and frameworks, reducing the learning curve and improving productivity. Additionally, the Web API feature includes a range of functions and capabilities that make it easy to customize the application’s behavior and integrate it with other systems.
2. Improved scalability
The Web API feature uses REST protocols, which allow for stateless communication between the client and server. This makes it easier to scale up the application to handle more users and data without impacting performance. Each request to the Web API feature includes all the information the server needs to process the request, reducing the need for complex session management and improving the overall scalability of the system.
3. Better security
The Web API feature includes built-in security features that help protect Dynamics CRM data from unauthorized access. It supports OAuth 2.0 authentication, which is an industry-standard protocol for securing API access. OAuth 2.0 allows for granular access control, ensuring that only authorized parties can access the data they need to perform their tasks. Additionally, the Web API feature supports SSL (Secure Sockets Layer) encryption, which protects data in transit between the client and server.
4. Increased flexibility
The Web API feature provides developers with a range of options for working with Dynamics CRM data. It supports a variety of operations, including create, read, update, and delete, as well as advanced querying and filtering capabilities. This flexibility allows developers to tailor their applications to specific business needs and integrate Dynamics CRM data with other systems and platforms.
In conclusion, Dynamics CRM Web API is a powerful tool for building business solutions that interact with the application. It provides a simplified development process, improved scalability, better security, and increased flexibility. By using the Web API feature, developers can work with Dynamics CRM data in a way that fits their needs and preferences, improving productivity and efficiency.
Benefits of Using Dynamics CRM Web API
The Microsoft Dynamics CRM Web API provides a platform for developers to interact with data within the CRM in a seamless manner. The API is a tool that allows easy integration of external systems with Dynamics CRM. Dynamics CRM is known for its robustness in managing customer information and integrating customer-facing systems such as marketing automation, salesforce automation, and customer service management. Dynamics CRM Web API provides an interface for developers to access the same data from external organizations. The benefits of using Dynamics CRM Web API include:
1. Easy Integration:
The Dynamics CRM Web API makes integration with external systems easy. Previously, custom applications needed to be developed to interact with CRM systems. However, with the Web API, developers can use HTTP and JSON/ODATA requests to access the data stored in the CRM. The API also supports multiple authentication methods such as OAuth2 which makes integration easier and secure.
The integration benefits of Dynamics CRM Web API extend to other Microsoft products such as Office 365, Power BI, and Azure. For instance, integration with Power BI allows for advanced reporting and analysis on the CRM data. Integration with Azure allows for the creation of custom applications using Azure services. Microsoft Office 365 integration provides users with access to CRM data without the need for separate authentication.
2. Improved Performance:
In the past, CRM systems relied on web services to access the data stored within the system. This means that the application had to go through multiple layers before it could access the actual data. Dynamics CRM Web API eliminates the need for web services and accesses data directly from the CRM. This means that applications built using the Web API experience faster data access and improved performance.
Additionally, Dynamics CRM Web API supports batch processing which allows multiple requests to be processed at the same time. This further improves the speed and efficiency of the API.
3. Increased Customizability:
The Dynamics CRM Web API enhances customization capabilities by allowing developers to access, update and delete data in the CRM. This means that businesses can tailor their CRM systems to suit specific business processes and workflows. Developers can create custom applications that enhance the functionality of the CRM using data from the API.
The Web API also supports client-side scripting languages such as JavaScript and uses the OData protocol which allows for easy filtering and querying of data. This provides developers with the ability to create dynamic, responsive and interactive applications that add value to businesses.
4. Improved Data Security:
The Dynamics CRM Web API provides a layer of security that ensures that only authorized personnel have access to the CRM data. The Web API supports multiple authentication methods such as OAuth2, Azure Active Directory, and Microsoft Account Authentication which ensure that data is protected from unauthorized access.
The API also supports data encryption to ensure that sensitive data is protected. Additionally, Dynamics CRM Web API complies with several security and privacy regulations such as the GDPR, HIPAA, and ISO 27001, making it a reliable and secure platform for businesses.
In conclusion, the Dynamics CRM Web API provides a powerful tool for developers to access, update and delete data on the CRM. The Web API enhances the functionality of the CRM by providing easy integration with external systems, improved performance, increased customizability, and improved data security. Developers can use the Web API to create custom applications and reports that enhance business operations and provide a competitive advantage.
How to Access Dynamics CRM Web API
The Dynamics CRM Web API provides a simple and efficient way to interact with the Dynamics CRM data. The API can be accessed by developers from any application or programming language that supports HTTP requests. Here are the steps that developers can follow to access the Dynamics CRM Web API.
Step 1: Register the application in Azure Active Directory
To access Dynamics CRM data through the Web API, developers have to first register the application within Azure Active Directory. Once the application is registered, Azure generates a unique client ID and a client secret that the developer can use to authenticate the API requests. The following steps describe how to register an application in Azure Active Directory:
- Sign in to the Azure portal using valid credentials.
- Select the Azure Active Directory option from the left-hand menu.
- Select App registrations and then click on the New registration button.
- In the Register an application form, enter the following details:
a. Name: Enter the name for the application.
b. Supported account types: Select the supported account types (Single tenant or Multi-tenant).
c. Redirect URI: Enter the redirect URI for your application.
d. Click the Register button.
- After the application is created in Azure Active Directory, it generates the client ID and client secret that the developer would use to authenticate API requests.
Step 2: Use client ID and secret to authenticate API requests
Developers are required to authenticate the API requests using the client ID and client secret generated in Azure Active Directory.
The following steps describe how to authenticate API requests:
- Get the access token: Developers can obtain the access token by making a POST request to the OAuth2 token endpoint using the client ID and client secret. This token is valid for a limited period and allows developers to make requests against the Dynamics CRM Web API.
- Include the access token in API requests: Developers need to include the access token in the Authorization header of all API requests they make.
Here’s an example of how to include the access token in the Authorization header:
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJ...
The token is a string of characters encoded in JSON Web Token (JWT) format.
Step 3: Construct the API request URL
Once developers have obtained an access token, they can use it to access the Dynamics CRM data.
Developers need to construct the API request URL carefully. The URL must be constructed in a specific order, starting with the Dynamics CRM Web API service root URL followed by the entity set name.
The following components need to be included in the API request URL:
- The Dynamics CRM Web API service root URL: This is the base URL for all requests to the API. The URL syntax is as follows:
https://{your organization name}.crm.dynamics.com/api/data/v9.2/
- The entity set name: This is the name of the entity set within Dynamics CRM that the developer wants to query. For example, if a developer wants to query the accounts entity set within Dynamics CRM, they would use the following URL:
https://{your organization name}.crm.dynamics.com/api/data/v9.2/accounts
- Query parameters: Developers can use a variety of query parameters depending on what they want to accomplish when querying the entity set. Some of the query parameters that can be used include $select, $filter, $orderby, and $expand.
For example, to retrieve all the accounts records, the request URL would be as follows:
GET https://{your organization name}.crm.dynamics.com/api/data/v9.2/accounts
Developers can use different query parameters to modify the output of the API request. For example, to retrieve only the name and primary email address of all the contacts, developers would use the following URL:
GET https://{your organization name}.crm.dynamics.com/api/data/v9.2/contacts?$select=name,emailaddress1
Using the Dynamics CRM Web API, developers can easily access and manipulate the Dynamics CRM data using a simple REST API. By following these steps, developers can quickly get started with accessing the Dynamics CRM Web API and interacting with the data.
Dynamics CRM Web API- Querying Data
Querying data in Dynamics CRM using Web API can help developers to retrieve data from multiple entities in Dynamics CRM. Developers can create complex query expressions and retrieve filtered data that can be used for further analysis and processing.
Query expressions in Web API can be used to retrieve data from entity records, entities with expanded relationships, filtered views, and aggregate data such as counts and sums. The following sections explain how to use the Dynamics CRM Web API to query data in Dynamics CRM.
Retrieve Entity Records
To retrieve entity records, developers can use a GET request to the Web API endpoint. The URI consists of the entity set name and a GUID that represents the record to retrieve. The following example shows how to retrieve an account entity record in Dynamics CRM:
Request: GET [organization URI]/api/data/v9.0/accounts(00000000-0000-0000-0000-000000000001)
Response:

The response retrieves the account entity record with the specified GUID. The response also includes the account entity attributes and their corresponding values.
Retrieve Entities with Expanded Relationships
To retrieve entities with expanded relationships, developers can use the $expand query option in the GET request. The expand option allows developers to retrieve related entities along with the parent entity record. The following example shows how to retrieve a contact entity record that includes its related account entity record:
Request: GET [organization URI]/api/data/v9.0/contacts(00000000-0000-0000-0000-000000000001)?$expand=parentcustomerid_account
Response:

The response retrieves the contact entity record with the specified GUID and the related account entity record. The response also includes the contact and account entity attributes and their corresponding values.
Retrieve Data from Filtered Views
To retrieve data from filtered views, developers can use the $filter query option in the GET request. The filter option allows developers to retrieve records that meet certain filtering criteria. The following example shows how to retrieve all account entity records that have a specific name:
Request: GET [organization URI]/api/data/v9.0/accounts?$filter=name eq ‘Adventure Works’
Response:

The response retrieves all account entity records that have the name ‘Adventure Works’. The response includes the account entity attributes and their corresponding values.
Retrieve Aggregate Data
To retrieve aggregate data such as counts and sums, developers can use the $count and $apply query options in the GET request. The count option allows developers to retrieve the total count of records that meet certain filtering criteria. The apply option allows developers to retrieve aggregate data such as counts and sums. The following example shows how to retrieve the count of account entity records that have a specific name:
Request: GET [organization URI]/api/data/v9.0/accounts/$count?$filter=name eq ‘Adventure Works’
Response:

The response retrieves the count of account entity records that have the name ‘Adventure Works’.
Using query expressions in Dynamics CRM Web API can help developers retrieve and filter data from multiple entities. The ability to retrieve aggregate data can provide valuable insights and metrics for further analysis and processing.
Dynamics CRM Web API- Updating/Deleting Data
In Dynamics CRM, Web API can be used to update or delete data from any entity in the system. In this article, we will discuss how to use Dynamics CRM Web API to update and delete data from entities.
Updating Data
Updating data in Dynamics CRM using Web API is quite simple. The process involves sending a PATCH request to the Web API endpoint for the entity you wish to update. The request must include all the properties that you want to update for the entity, along with the entity’s ID as a parameter in the URL.
For example, to update the details of an account whose ID is “accountid,” we would send a PATCH request to the following endpoint:
https://[your-crm-url]/api/data/v[api-version]/accounts(accountid)
The request will contain the updated values for the entity and should look something like this:
var data = {
name: "New Account Name",
address1_city: "London",
address1_country: "UK"
};
var req = new XMLHttpRequest();
req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v[api-version]/accounts(accountid)", false);
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.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
//success action
} else {
//error action
}
}
};
req.send(JSON.stringify(data));
This will update the account record with the updated field values we specified in the request.
Deleting Data
Deleting data in Dynamics CRM using Web API is also quite simple. The process involves sending a DELETE request to the Web API endpoint for the entity you wish to delete, along with the entity’s ID as a parameter in the URL.
For example, to delete an account whose ID is “accountid,” we would send a DELETE request to the following endpoint:
https://[your-crm-url]/api/data/v[api-version]/accounts(accountid)
The request will contain the entity’s ID and should look something like this:
var req = new XMLHttpRequest();
req.open("DELETE", Xrm.Page.context.getClientUrl() + "/api/data/v[api-version]/accounts(accountid)", 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.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204 || this.status === 1223) {
//success action
} else {
//error action
}
}
};
req.send();
This will delete the account record with the specified ID.
It’s important to note that deleting an entity will also delete all its related records, so it should be done with caution. Additionally, if there are any plugins or workflows set up to run on delete, these will also be triggered when using Web API to delete a record.
Conclusion
In conclusion, Dynamics CRM Web API is a powerful tool that allows developers to update and delete data from any entity in the system. By sending HTTP requests to the Web API endpoints, we can easily update and delete data in Dynamics CRM without needing to use the user interface. However, it’s important to keep in mind that any changes to the system should be done with caution, and that Web API requests can trigger plugins and workflows, which can have unintended consequences.