This blog post will guide you through the steps to call a custom API in Dynamics 365 using Postman, a widely used tool for API testing and development. By the end of this tutorial, you will have a solid grasp of setting up Postman, authenticating your requests, and interacting with custom API endpoints in D365.

Step 1: Obtain an Access Token

To call a custom API in D365, you first need to obtain an access token. This token verifies that you are an authorized user.

  1. Set Up the Request to Obtain the Access Token:
  • URL: https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token
    • Replace {tenant_id} with your actual tenant ID/Azure Directory ID.
  • HTTP Method: POST
  • Headers:
    • Content-Type: application/x-www-form-urlencoded
  • Body:
    • Select x-www-form-urlencoded.
    • Add the following key-value pairs:
      • client_id (retrieve from Azure AD)
      • client_secret (retrieve from Azure AD)
      • grant_type: client_credentials
      • scope: https://{your_dynamics_instance_url}/.default
        • Replace {your_dynamics_instance_url} with your actual Dynamics 365 URL.
  1. Send the Request:
    • After sending this request, you will receive an access token in the response. This token is needed for subsequent API calls to D365.

Step 2: Make the API Call to D365

With the access token, you can now call your custom API in D365.

  1. Set Up the API Call Request:
  • URL: {web_api_url}/{custom_api_name}
    • To get the Web API URL, go to Settings > Customizations > Developer Resources > Copy Service Root URL (which is API Url).
  • HTTP Method: POST
  • Authorization:
    • In the Authorization tab, select Bearer Token.
    • Paste the access token obtained from Step 1.
  • Headers:
    • Content-Type: application/json
  • Body:
    • Select raw and JSON.
    • Add your custom API request parameters in JSON format. For example:

{

“OpportunityID”: “sample opportunity”,

“QuoteNumber”: “QUO-01011-S302CC”,

                           “QuoteBody”: “Quote1”,

                           “Status”: “Generated”

                       }

2. Send the Request:

  • Once you send this request, you should receive a response from the custom API, which will include the ResponseCode.

By following these steps, you can successfully call a custom API in D365 using Postman.