Is it possible to Create/Update Application User in Dynamics 365 Programmatically?

By | July 6, 2018

You may have heard about the Application user in Dynamics 365. The Application user is a non-licensed and non-interactive user in the Dynamics 365 that we can use to connect to Dynamics 365 services to perform operations.

Have you come across a requirement where you need to create/update Application User programmatically and do you think it is possible?

Recently, we had a requirement where we had to create an Application User in Dynamics 365 programmatically. And, after researching it, we came to know that it is possible!

In this blog, we will illustrate how we can create/update the Application user programmatically.

Programmatically Creating or Updating Application User in Dynamics 365

While creating an Application User from Application Form manually, we have to pass the below mandatory fields.

  1. First Name
  2. Last Name
  3. Primary Email
  4. Application ID (that we get from Azure AD)

After you click on save button, the Application ID URI, Azure AD Object ID fields get auto-populated.

If you try to do the same thing using either JavaScript (Web API) or C# code (bypassing above mentioned four fields to entity object to create), you will get the following error,

“An unexpected error occurred”

While creating an Application User, we must pass the Business Unit ID field along with the fields mentioned above.

So to create an Application User, we must pass following fields to an entity object,

  1. First Name
  2. Last Name
  3. Primary Email
  4. Application ID (that we get from Azure AD)
  5. Business Unit ID

Below is the sample code that shows how to create Application User using Web API at the client side.


Here, we first retrieved the Business Unit ID and then we passed this Business Unit ID to create the Application User along with other fields.

You can see that we are checking whether an Application User already exists with matching Application ID in the System. If matching Application User is found, then we are updating existing Application User, else we create a new Application user.


It is possible to create Application user either at client side (using JavaScript) or server side (using plugin, workflow assembly or external tools). We need to make sure that we are passing all the required fields, i.e. First name, Last Name, Email Address, Application ID and Business Unit ID.


Leave a Reply

Your email address will not be published. Required fields are marked *