Dataverse D365 REST Web Api using client secret From Postman or Power Automate desktop (PAD) .

 
How to call Dataverse REST Web Api from postman or power automate desktop.

Note: 
<Value>: Either custom value or value from previous steps.
- D365 environment URL
- O365 Entra/*Global admin.  


----X----

Let's get started.

Register an app using MS Entra Platform: 

Go to: https://entra.microsoft.com/ -> Identity -> Applications -> App registrations -> New registration

Official link: https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-register-app

 


Name: <Provide Name>

Supported account types: Single tenant.

Redirect URI: https://localhost

Update Manifest file: Set oauth2AllowImplicitFlow to true.


Grant Permission to access Dataverse (AKA Dynamic CRM)

API Permissions -> "+ Add a permission"




"User_impersonate" -> "Add permissions"



Grant API Permissions (Note: Only Global admin can grant permission)

Once permission is granted you will see Status as "Granted" with green check mark. 


 Create Client Secret Value

Please save/store Value in separate Notepad called Keys / file (This will be password for app, so keep this value at secure place)

Let's go to overview page and save few values so we can use same in later configuration.

Client ID, Tenant ID


We will need one more item: Dynamic 365 environment URL

Go to: https://make.powerapps.com/ -> Login -> Select Correct Environment from top right side.

Click Gear Icon from top right -> Advanced Setting -> This will open legacy D365 UI and site will have URL with Dynamics in it. This is your D365 URL. 

You will only need till .com, remove everything after that and replace with .default

What you get: https://orgf0d00000.crm.dynamics.com/main.aspx?settingsonly=true#16944766

What you need: https://orgf0d00000.crm.dynamics.com/.default

Let's grant App access to Dataverse.

Go to: Power Platform admin center. 

Power Platform admin center (microsoft.com)

Environments -> <Select Same Environment>.

Select "S2s apps"

 "+ New app user" -> "+ Add an app" -> "Business Unit" -> Security Role  -> System Administer

+ Add an app : Select App we just created in Entra Platform above.




Note: Please do not use "System Administer" in Production, create a custom role and assign here.

Now we are all done with O365, and we have Client ID, Tenant ID, Client Secret (Value), D365 URL.

Let's open Postman.

Collection -> New Collection -> New Post Request -> Get Token

URL: https://login.microsoftonline.com/<Tenant ID>/oauth2/v2.0/token

Body

client_Id <Client ID>
client_secret <Client Secret Value>
grant_type client_credentials
Scope <D365 URL> 


Header

Host : login.microsoftonline.com 


Click SEND from Postman

You will get "200 OK" Status then everything is configured correctly, if not validate all keys, permissions.

You should see Bearer access_token in response

Save this token as this is our key until "expires_in"


Let's use this token and retrieve Dataverse table list.

Let's get Dynamics 365 API URL 

Click Gear from Power Apps site -> Check Environment -> Developer Resource -> Web API End Point

https://make.powerapps.com/

 


Save Web API End Point to "Keys Notepad"

Create another request in Postman collection.

Header 

Authorization:  Bearer <access token for 1st postman request>

Your get request should look like below.

 



If you get result like below all great:


 


Let's try to do same using Power Automate Desktop (PAD)

Invoke Web Service



Use same keys as Postman (just add in body as below) 

grant_type=client_credentials&client_id=<cliend id>&client_secret=<Client secret value>&Scope=https://<CRM Domain>.crm.dynamics.com/.default

Disable "Encode request body"


Convert JSON to we can use token in next step

Call API to get all table details.  



Feel free to ask any questions in comments.

NOTE: 

Another area to consider when you are using custom permission in Production for accessing tables is D365 table:

Go to: Power Platform admin center: https://admin.powerplatform.microsoft.com/

Select Environment -> Select custom table -> Permission -> Organization.




 

 

 

 

 





 

 




















 


Comments

Popular posts from this blog

Chrome Extension to auto refresh Power BI report.

How to call SharePoint online rest APIs using postman?