D365 – Using API Testing Tools to Access CRM

Introduction

I usually use API testing tools like Postman and Apifox to test web services, which makes it convenient to debug interfaces. Dynamics 365 also provides many standard interfaces.

Today, I will try to connect to Dynamics 365 using Apifox and attempt to use the standard interfaces.

Prerequisites:

  1. You are an “Administrator” user, otherwise you cannot access the Azure Active Directory portal.
  2. Have API testing tools installed, such as Postman, Apifox, etc.

Detailed Steps

1. Get ClientId and ClientSecret

Step 1. Register an Application

(1) Visit and log in to the Azure Portal.

(2) In the search box at the top, search for “App registrations” and click on it.

Register Application-01

(3) Click on “New registration.”

Register Application-02

(4) On the pop-up page, enter a meaningful application name (e.g., D365-GetClientSecret) -> Select supported account types -> Click the “Register” button.

Register Application-03

Step 2. Get ClientId

After completing Step 1, we can find the Application ID (ClientId) from the “Overview” section and copy it to Notepad for later use.

Get ClientId

2. Configure Application for ①Authentication, ②Manifest, ③API Permissions

Step 1. Add Authentication

Authentication -> “+ Add a platform” -> Select Web

Add Authentication-01

Enter http://localhost -> Check “Access tokens (used for implicit flow)”

Add Authentication-02

Step 2. Modify “Manifest” Configuration File

Set the following 2 properties to true and save.

  1. AllowPublicClient
  2. oauth2AllowImplicitFlow

Modify “Manifest” Configuration File

Step 3. Add API Permissions

(1) API Permissions settings -> “+ Add a permission”

Add API Permissions-01

(2) “APIs my organization uses” -> Search for Dataverse -> Select Dataverse

Add API Permissions-02

(3) Select delegated permissions -> Check permissions -> Add permissions

Add API Permissions-04

3. Postman Connection Testing

(1) Create a new Collection and give it a meaningful name, e.g., using-postman-call-crm

Create Postman Collection

(2) Create an Environment

Create Postman Environment

(3) Add environment variables

# Variable Description/Example
1 url Your CRM environment URL
2 clientid ClientId of your application, as Geted in “Step 2. Get ClientId”
3 version 9.0
4 webapiurl {{url}}/api/data/v{{version}}/
5 callback http://localhost
6 authurl https://login.partner.microsoftonline.cn/common/oauth2/authorize?resource={{url}}

Add Environment Variables in Postman

(4) Create a new request

Create Postman Request

(6) Configure getting Token information for the request:

Configure Token Information for Postman Request

Clicking on Get New Access Token will prompt a login box. Fill in your account and password to Get the Token information.

Get Token in Postman

Copyright Notice

Author: Donghai

Link: https://gdhblog.com/posts/d365/dynamics-365-api-testing-crm-guide/

License: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Please attribute the source, use non-commercially, and maintain the same license.

Comments

Start searching

Enter keywords to search articles

↑↓
ESC
⌘K Shortcut