D365 Data Entities
In this article, we will learn how to set up Postman to call Data Entities in Dynamics 365 Finance and Operations (D365FO) using X++. Postman is a powerful tool that allows developers to test APIs and work with data from external systems easily.
By the end of this guide, you’ll know how to:
- Configure Postman to connect to your D365FO environment.
- Authenticate your connection using OAuth 2.0.
- Make API calls to interact with D365FO Data Entities.
Whether you are a beginner or looking to streamline your integration process, this guide will make it easy to test and explore D365FO data without needing complex setups. Let’s get started!
What are Data Entities in D365FO?
In Dynamics 365 Finance and Operations (D365FO), Data Entities are like organized containers or “bridges” that help you work with data. Think of them as a simplified way to interact with complex data stored in the system. Instead of dealing with multiple complicated tables directly, a data entity provides a straightforward structure, so you can easily view, add, update, or export data.
For example:
- If you want to work with customer information, instead of looking at several technical tables, you can use a Customer data entity to get all customer-related data in one place.
- It’s like asking for a “ready-made sandwich” instead of hunting for bread, cheese, and toppings individually.
What are Data Entities Used For?
- Integration with Other Systems:
Data entities allow external systems or apps (like Power BI, Power Apps, or third-party tools) to communicate with D365FO without getting into the complex structure of its database. It provides an easy way to exchange data. - Data Import/Export:
You can use data entities to import data into D365FO or export data out of it. For instance, if you need to upload a list of vendors or export financial reports, data entities make it easy. - Simplifying Customizations:
For developers, data entities simplify working with data in X++. Instead of writing queries for multiple tables, you can use a data entity to work with the relevant data in one go. - OData API Access:
Data entities are exposed via OData APIs, meaning external tools (like Postman or Excel) can call them directly to fetch or send data. This is where setting up Postman comes into play, as you use it to test and work with these APIs. - Data Validation & Transformation:
Entities often handle validation and business logic, ensuring the data going in or out of the system follows D365’s rules and formats.
What You’ll Need
Before we dive into setting up Postman, make sure you have the following essentials ready:
- Postman Installed: Download and install Postman from their official website: Postman Downloads. This is the tool we’ll use to send API requests to your D365FO environment.
- Directory ID (Tenant ID): This is a unique identifier for your Azure Active Directory (AAD) tenant.
- Client ID (Application ID): This represents the application you registered in Azure Active Directory. It’s required to authenticate your connection to D365FO.
- Client Secret: The client secret is like a password for your application. You’ll need this to authenticate the API requests securely.
- D365FO Environment URL: This is the URL of the Dynamics 365 environment you want to connect to.
Create Get Token Request In Postman
Open Postman.
Click the ‘New’ button in the top right corner. Select ‘HTTP Request’
In the main window, change the request type to be ‘Post’.
Then enter in the URL to be the following. Replace <Directory ID> to be your Directory ID found in the Azure Portal.
https://login.microsoftonline.com/<Directory ID>/oauth2/v2.0/token
Next, go to the ‘Headers’ tab in Postman and set the required values. Most of these headers should already be pre-filled by default. However, you’ll need to update the Host header to login.microsoftonline.com
.
Click on the Body tab and specify the following Key Value pairs.
- client_id: Enter the Client ID (Application ID) from the Azure Portal. This identifies the app you registered.
- client_secret: Provide the Client Secret from the Azure Portal. This acts like a password for secure authentication.
- grant_type: Set this to
client_credentials
. This specifies the type of authentication you’re using. - scope: Use the URL of your D365FO instance, followed by
/.default
.
https://<D365 URL>/.default
Click the ‘Save’ button in the top-right corner to save your request.
Next, click the ‘Send’ button to execute the request. If everything is set up correctly, you should see a response similar to this in the response body:
- The access_token field will contain a long string, which is your authentication token.
- The Status will display 200 OK, indicating the request was successful.
This access token is what you’ll use in subsequent API calls to interact with your D365FO environment.
Store the Access Token In An Environment Variable
We’ll need to use the access_token value from the previous step every time we make a call to D365FO. Keep in mind that this token expires in about an hour. While copying and pasting the token each time is an option, there’s a much more efficient way to handle this: by storing the token in an environment variable in Postman.
Here’s how to set it up:
- In Postman, click the ‘New’ button.
- From the options, select ‘Environment’ to create a new environment where you can store the token.
In the dialog that opens specify a name for the environment. In the first line, enter the text ‘access_token’ under the variable column. Then click the Add button.
Now go back and select the ‘Get Token’ request.
Select the ‘Tests’ tab.
Enter the following code. This takes the access_token value in the response of this request, and stores it in the environment variable named ‘access_token’.
var jsonData = pm.response.json(); postman.setEnvironmentVariable("access_token", jsonData.access_token); Click Save.
Setup Postman Request To D365 Data Entity
Finally, we’re ready to make a request to a D365FO Data Entity.
- In Postman, click the ‘New’ button.
- From the options, select ‘Request’ to create a new API request.
This will allow you to interact with the D365 Data Entity and test retrieving or modifying data directly from your environment.
Set the request type to ‘Get’.
Specify the following text in the URL field. Replace <D365 URL> with the URL you use to access the D365 environment.
https://<D365 URL>/data/<EntityName>
In the Headers tab, specify the following Key Value Pairs.
Most of the required key-value pairs will be pre-filled. However, you need to manually set the Authorization header as follows:
- Set the Authorization value to
Bearer {{access_token}}
.
This tells Postman to dynamically replace{{access_token}}
with the value stored in the access_token environment variable.
If you haven’t set up an environment variable, you can manually copy and paste the long access token value from the first call into this field. Just make sure to keep the Bearer
prefix intact, followed by the token.
Steps to complete the request:
- Click ‘Save’ to save your request.
- Click ‘Send’ to execute it.
If everything is configured correctly, you’ll receive:
- A 200 OK status in the response, indicating success.
- The response body will contain customer data in JSON format.
In this article, we’ve walked through the process of setting up Postman to call D365FO Data Entities. By using the access token for authentication and setting up environment variables in Postman, you can streamline your interactions with D365FO APIs. This process makes it easy to test and integrate D365FO with other systems, helping you manage and retrieve data efficiently.
With your Postman setup complete, you now have the tools to make API calls to your D365FO environment, fetch customer data, and explore other Data Entities. Remember, the access token expires after an hour, so you’ll need to refresh it regularly to continue making successful requests.
This setup is just the beginning — from here, you can build powerful integrations and automate processes to enhance your D365FO experience.