web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

How to create application user by code?

(1) ShareShare
ReportReport
Posted on by 15

I'm creating app in aad.portal.azure and succeed integrate with CRM, but I miss one step that I'm creating application user manually through admin.powerplatform.microsoft, how can I create user by code?

note: I'm using nodejs and for authentication I use url

login.microsoftonline.com/${tenantid}/oauth2/v2.0/authorize?client_id=${clientId}&response_type=code&redirect_uri=${redirectUri}&response_mode=query&scope=globaldisco.crm.dynamics.com/.default offline_access

I use scope=globaldisco.crm.dynamics.com/.default because i need to get the crm ApiUrl, but if I use that scope I cant create application user

I have the same question (0)
  • Suggested answer
    Tamilarasu Arunachalam Profile Picture
    587 on at

    Hi Firman,

    You can create application by code. Please refer the below link

    https://www.inogic.com/blog/2018/07/is-it-possible-to-createupdate-application-user-in-dynamics-365-programmatically/

    If you found this useful, like or verify my answer

  • tech-44 Profile Picture
    on at

    Creating an application used by code is a simple process that can be complete quickly. The key to creating a practical application user by code is understanding the basic concepts and using them correctly. By following these tips, you can create an efficient and successful user interface for your application.

  • Firman Profile Picture
    15 on at

    which tips?

  • Firman Profile Picture
    15 on at

    I have tried it but doesn't know how to test in case user application is not created yet because i already create it manually and i cant find how to delete it, I also have tried deactivate user application that I create manually and when try to create by that code it suddenly cant access the CRM dataverse

  • Suggested answer
    Naveen Ganeshe Profile Picture
    3,397 User Group Leader on at

    Hi Firman,

    To create an application user in admin.powerplatform.microsoft using code in Node.js, you will need to use the Microsoft Graph API. The Microsoft Graph API allows you to access and manage various resources within the Power Platform, including users. Here's an example of how you can use the Microsoft Graph API to create an application user:

    1. First, you will need to register an app in Azure Active Directory. This will give you an clientId and clientSecret which will be used for authentication.

    2. Once you have the clientId and clientSecret, you can use the msal library to obtain an access token. Here's an example of how to do this:

      const msal = require("msal");
      
      const clientId = "";
      const clientSecret = "";
      
      const client = new msal.ConfidentialClientApplication({
        auth: {
          clientId: clientId,
          clientSecret: clientSecret,
          authority: "https://login.microsoftonline.com/common",
          tokenCache: new msal.TokenCache()
        }
      });
      
      const scopes = ["https://graph.microsoft.com/.default"];
      
      const getAccessToken = async () => {
        try {
          const authResponse = await client.acquireTokenForClient(scopes);
          return authResponse.accessToken;
        } catch (error) {
          console.log("Error getting access token: "   error);
        }
      };
    1. Once you have the access token, you can use it to make a POST request to the Microsoft Graph API to create the user. Here's an example of how to do this using the request library:

    const request = require("request");
    const token = await getAccessToken();
    
    const options = {
      method: "POST",
      url: "https://graph.microsoft.com/v1.0/users",
      headers: {
        "Authorization": "Bearer "   token,
        "Content-Type": "application/json"
      },
      json: true,
      body: {
        "accountEnabled": true,
        "displayName": "Application User",
        "passwordProfile": {
          "forceChangePasswordNextSignIn": true,
          "password": "Pass@word1"
        },
        "userPrincipalName": "applicationuser@yourdomain.onmicrosoft.com"
      }
    };
    
    request(options, (error, response, body) => {
      if (error) {
        console.log("Error creating user: "   error);
      } else {
        console.log("User created successfully: "   JSON.stringify(body));
      }
    });

    You can also use other libraries like axios or node-fetch for making HTTP call for the above steps

    Please note that this is just an example and the request body may vary based on the required fields of the application user. You will also have to check the permissions of your app registration to ensure that it has the necessary permissions to create an application user. You can refer to the Microsoft Graph API documentation for more information on creating application users and managing users within the Power Platform.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 96 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans