I am trying to invoke a Power Automate Desktop bot using web api, as per the instructions provided in the below article.
https://learn.microsoft.com/en-us/power-automate/developer/desktop-flow-public-apis
I created an App registration with user_impersonation privilege and I am able to get the bearer token as well. But when I hit the below API using Postman, I am getting an error stating "The user is not a member of the organization".
POST https://[Organization URI]/api/data/v9.2/workflows([Workflow ID])/Microsoft.Dynamics.CRM.RunDesktopFlow HTTP/1.1
Can someone advise where this has to be added or what am I missing?
Regards, Ganesh.
The error usually occurs if you missed creating Application user by adding
Application ID
of Azure AD application.
I registered one Azure AD application and granted API permission like this:
Now, I generated access token using client credentials flow via Postman with below parameters:
POST https://login.microsoftonline.com/<tenantID>/oauth2/token
grant_type:client_credentials
client_id:<appID>
client_secret:<secret>
resource: https://orgxxxxxx.crm.dynamics.com
Response:
When I used this token to run below sample API, I got same error as you like below:
GET https://orgxxxxxxx.crm.dynamics.com/api/data/v9.2/WhoAmI
Response:
To resolve the error, you need to create one Application user by adding Application ID
of your Azure AD application.
Go to Power Platform admin center -> Environments -> Select your organization -> Settings -> Select Application users
Now, click on New app user
option to create Application user like below:
Enter your Azure AD application name or ID in search bar and add it like this:
Now, select your organization under Business Unit
and make sure to assign System Administrator role to create application like below:
After creating application user, I generated token again and got the response successfully when I used it to run sample API like this:
GET https://orgxxxxxxx.crm.dynamics.com/api/data/v9.2/WhoAmI
Response:
In your case, make sure to create Application user by assigning proper role following the above steps.