dynamics-365power-automate-desktopazure-app-registration

Invoking Power Automate Desktop bot using Web API


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.


Solution

  • 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:

    enter image description here

    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:

    enter image description here

    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:

    enter image description here

    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

    enter image description here

    Now, click on New app user option to create Application user like below:

    enter image description here

    Enter your Azure AD application name or ID in search bar and add it like this:

    enter image description here

    Now, select your organization under Business Unit and make sure to assign System Administrator role to create application like below:

    enter image description here

    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:

    enter image description here

    In your case, make sure to create Application user by assigning proper role following the above steps.