Tue, 02/04/2020 - 15:15 By Stéphan Drouard Contributor Lloyd Sebag
postman

Presentation

A lot of developer is using postman to test webservices. Let’s see how to connect to dynamics 365 via postman using an identification token in order to test webAPI requests.

Prerequisites

Before starting this tutorial, you must:

  • Install Postman
  • Access to a Dynamics 365 online instance with an administrator user
  • Access to Azure Active Directory Portal

First step: Register a new Dynamics 365 App

Before starting using Postman, you must register a new Dynamics 365 App. Basically, you will create a unique App ID with specific right to access your dynamics 365.

First you need to connect to Azure Portal with administrator credentials.

From the homepage, click on Azure Active Directory -> App Registration -> New Registration

Screen1

In the Application registration form, you have to enter some information:

  • Name: this is the name of the registration app. Enter a meaningful one.
  • In the Supported account types part, select Accounts in any organizational directory  
  • Set the redirectUrl. In our case, let’s use Web and http://localhost

Then click on Register

Screen2

Your application is register. From the overview, you can find the application id. Copy it somewhere you will need it later in Postman.

Screen3

Now let’s open the manifest.

Screen4

 

Set the “AllowPublicClient” and “oauth2AllowImplicitFlow” to true.

Then Save it.

Now go on API permissions

Screen5

Click on Add a permission

Screen6

Select Dynamics CRM under the API Microsoft Graph tab.

Screen7

Click on Delegated permissions, check the options and click on Add permissions.

Your app is now registered and setup!

Second Step: Setup your Postman environment

Open Postman and create a new environment 

Screen8

Let’s setup the following variables:

  • url: Your Dynamics 365 URL
  • clientid: ‘Application ID’ from Azure registered app, generated in the first step
  • version: Dynamics version
  • webapiurl: Set this to {{url}}/api/data/v{{version}}/
  • callback: ‘Home page’ value from Azure registered app, set in 2.2. In our case: http://localhost.
  • authurl: Set this to https://login.microsoftonline.com/common/oauth2/authorize?resource={{url}}

Screen9

Third Step: Generate oAuth Access Token

Now your environment is set up, we are going to generate the oAuth access Token. This is a one-time operation for a single D365 instance.

Select your newly created environment and go on the authorization tab.

Select oAuth 2.0 in the Type list and click on Get New Access Token.

Screen10

In the “Get new Access Token screen”, fill in the fields as below. (you are free to change the token name)

Screen11

Then click on Request Token.

System will prompt you for credentials, pass your O365 credentials.

You may be asked some permission. Check the box and click on Accept.

Screen12

If everything’s went fine you should get this screen.

 

Screen13

Click on Use Token.

Now your Postman is setup and you can execute requests!

Test: WhoAmI

Let’s now try excuting a WhoAmI request.

Select your newly created environment.

Select ‘GET’ operation and set the URL as {{webapiurl}}WhoAmI

Select Request Header in the “Add authorization data to

Click on Send.

You should get “200 OK” response up on success.

 

Screen14

 

Tags

Add new comment

Image CAPTCHA
Enter the characters shown in the image.