Grant an appRoleAssignment to a user

Namespace: microsoft.graph

Use this API to assign an app role to a user. To grant an app role assignment to a user, you need three identifiers:

  • principalId: The id of the user to whom you are assigning the app role.
  • resourceId: The id of the resource servicePrincipal that has defined the app role.
  • appRoleId: The id of the appRole (defined on the resource service principal) to assign to the user.


One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions.

Permission type Permissions (from least to most privileged)
Delegated (work or school account) AppRoleAssignment.ReadWrite.All, Directory.AccessAsUser.All
Delegated (personal Microsoft account) Not supported.
Application AppRoleAssignment.ReadWrite.All

HTTP request

POST /users/{id | userPrincipalName}/appRoleAssignments


As a best practice, we recommend creating app role assignments through the appRoleAssignedTo relationship of the resource service principal, instead of the appRoleAssignments relationship of the assigned user, group, or service principal.

Request headers

Name Description
Authorization Bearer {token}. Required.
Content-Type application/json. Required.

Request body

In the request body, supply a JSON representation of an appRoleAssignment object.


If successful, this method returns a 201 Created response code and an appRoleAssignment object in the response body.



Here is an example of the request.

Content-Type: application/json

  "principalId": "cde330e5-2150-4c11-9c5b-14bfdc948c79",
  "resourceId": "8e881353-1735-45af-af21-ee1344582a4d",
  "appRoleId": "00000000-0000-0000-0000-000000000000"

In this example, note that the value used as the user id in the request URL (cde330e5-2150-4c11-9c5b-14bfdc948c79) is the same as the principalId property in the body.


Here is an example of the response.

Note: The response object shown here might be shortened for readability.

HTTP/1.1 200 OK
Content-type: application/json

  "@odata.context": "$metadata#users('cde330e5-2150-4c11-9c5b-14bfdc948c79')/appRoleAssignments/$entity",
  "id": "5TDjzVAhEUycWxS_3JSMeY-oHkjrWvBKi7aIZwYGQzg",
  "deletedDateTime": null,
  "appRoleId": "00000000-0000-0000-0000-000000000000",
  "createdDateTime": "2021-02-15T10:31:53.5164841Z",
  "principalDisplayName": "Megan Bowen",
  "principalId": "cde330e5-2150-4c11-9c5b-14bfdc948c79",
  "principalType": "User",
  "resourceDisplayName": "dxprovisioning-graphapi-client",
  "resourceId": "8e881353-1735-45af-af21-ee1344582a4d"