Business Central Bound Actions and Postman
In this blog post, we will walk you through the process of triggering a bound action in Dynamics 365 Business Central using Postman. Postman is a popular tool for testing APIs, and it can be very useful for developers working with Dynamics 365 Business Central to test and debug their API calls.
Prerequisites
Before we get started, ensure you have the following:
A Dynamics 365 Business Central environment
Postman installed on your computer
Configure an App Registration in Microsoft Entra ID
The first step is to configure an app registration in Microsoft Entra ID (formerly Azure AD). This app registration will allow your application to authenticate against Dynamics 365 Business Central and obtain the necessary access tokens.
Follow these steps to configure the app registration:
Log in to the Azure portal (https://portal.azure.com).
Navigate to the Microsoft Entra Id service.
In the left-hand menu, select App registrations, and then click on New registration.
Enter a name for your app, such as "Business Central API Access".
Choose the supported account types, typically "Accounts in this organizational directory only (single tenant)".
For the Redirect URI, select "Web" and enter a URL where the token will be sent after authentication (e.g., https://businesscentral.dynamics.com/OAuthLanding.htm).
Click Register to create the app registration.
Once the app registration is created, you will need to note the following details:
Client ID (also known as Application ID)
Tenant ID
Client Secret (which you'll create under Certificates & secrets)
This app registration essentially sets up a trust relationship between your application and Microsoft Entra ID, enabling secure communication and authentication.
Develop and Obtain Your Business Central Bound Action API Endpoint
First, you need to develop the bound action in Dynamics 365 Business Central. The detailed steps for developing a bound action can be found in our previous blog post [Bound Actions in Dynamics 365 Business Central].
After developing the bound action, you will have the URL endpoint for your API. This endpoint typically looks something like this:
Take note of this URL as you will need it in the following steps.
Generate an Access Token
To authenticate your requests, you need to generate an OAuth token. Follow these steps:
In Postman, create a new GET request and enter the Business Central token endpoint URL (e.g., [https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token]).
In the Body tab, select x-www-form-urlencoded.
Add the following key-value pairs:
grant_type: client_credentials
client_id: {your_client_id}
scope: {your_scope}
client_secret: {your_client_secret}
Click Send.
Once the token is generated, copy the access_token from the response.
Use the access_token from the GET request and send it in the Authorization header of a POST request to the bound action endpoint.
Configure Your Postman Request
Open a new request tab in Postman and set the HTTP method to POST.
Enter the API endpoint URL you noted earlier, adding the specific endpoint for the bound action. For example: [https://api.businesscentral.dynamics.com/v2.0/<tenant-id>/<environment>/api/APIPublisher/APIGroup/companies(<company-id>)/EntitySetName(<ODataKeyFields>)/Microsoft.NAV.procedureName()]
In the Headers tab, add the following headers:
Authorization: Bearer {your_access_token}
Content-Type: application/json
In the Body tab, select raw and set the type to JSON. Enter the JSON payload required for your bound action. For example:
Send the Request
Once you have set up your request, click the Send button in Postman. If everything is configured correctly, you should receive a response from the API indicating that the bound action was successfully triggered.
Review the Response
Examine the response returned by Dynamics 365 Business Central. If the request was successful, you will see a status code of 200 along with any relevant data. If there was an error, the response will contain details to help you troubleshoot the issue.
Conclusion
By following these steps, you should be able to trigger a bound action in Dynamics 365 Business Central using Postman. This method allows you to test your API endpoints efficiently and ensure that your integrations are working as expected. Demonstrating how to initiate an integration process from multiple different sources is an invaluable skill that makes facilitating integrations much easier for integration partners. Happy testing!
Comentários