Azure AD Graph API reference
The Azure Active Directory (AD) Graph API is an OData 3.0 compliant service that you can use to read and modify objects such as users, groups, and contacts in a tenant. Azure AD Graph API exposes REST endpoints that you send HTTP requests to in order to perform operations using the service. Use the Try It! experience to change the parameters of selected operations and observe the responses that are returned from the demo tenant.
A successful request to the Graph API must be addressed to a valid endpoint and be well-formatted, that is, it must contain any required headers and, if necessary, a JSON payload in the request body. The app making the request must include a token received from Azure AD that proves that it is authorized to access the resources targeted by the request. The app must be able to handle any responses received from the Graph API.
Important
Azure AD Graph API functionality is also available through Microsoft Graph, a unified API that also includes APIs from other Microsoft services like Outlook, OneDrive, OneNote, Planner, and Office Graph, all accessed through a single endpoint with a single access token.
Authentication and Authorization
Every request to the Graph API must have a bearer token issued by Azure Active Directory attached. The token carries information about your app, the signed-in user (in the case of delegated permissions), authentication, and the operations on the directory that your app is authorized to perform. This token is carried in the Authorization
header of the request. For example (the token has been shortened for brevity).
The Graph API performs authorization based on OAuth 2.0 permission scopes present in the token. For more information about the permission scopes that the Graph API exposes, see Graph API Permission Scopes.
In order for your app to authenticate with Azure AD and call the Graph API, you must add it to your tenant and configure it to require permissions (OAuth 2.0 permission scopes) for Windows Azure Active Directory. For information about adding and configuring an app, see Integrating Applications with Azure Active Directory.
Azure AD uses the OAuth 2.0 authentication protocol. You can learn more about OAuth 2.0 in Azure AD, including supported flows and access tokens in OAuth 2.0 in Azure AD.
Endpoint Addressing
To perform operations with the Graph API, you send HTTP requests with a supported method - typically GET, POST, PATCH, PUT, or DELETE -- to an endpoint that targets the service, a resource collection, an individual resource, a navigation property of a resource, or a function or action exposed by the service. Endpoints are expressed as URLs.
The Graph API performs authorization based on OAuth 2.0 permission scopes present in the token. For more information about the permission scopes that the Graph API exposes, see Graph API Permission Scopes.
In order for your app to authenticate with Azure AD and call the Graph API, you must add it to your tenant and configure it to require permissions (OAuth 2.0 permission scopes) for Windows Azure Active Directory. For information about adding and configuring an app, see Integrating Applications with Azure Active Directory.
Azure AD uses the OAuth 2.0 authentication protocol. You can learn more about OAuth 2.0 in Azure AD, including supported flows and access tokens in OAuth 2.0 in Azure AD.
The following components comprise the URL:
- Service Root: The service root for all Graph API requests is
https://graph.windows.net
. - Tenant Identifier {tenant_id}: The identifier for the tenant that the request targets.
- Resource path {resource_path}: The path to the resource -- for example, a user or a group -- that the request targets.
- Graph API Version {api_version}: The version of the Graph API targeted by the request. This is expressed as a query parameter and is required.
Note
In some cases, when reading resource collections, OData query parameters can be added to the request to filter, order, and page the result set. For more information, see the OData query parameters section in this topic.
Tenant Identifier
You can specify the target tenant of a request in one of the following ways.
By tenant object ID: The GUID that was assigned when the tenant was created. This can be found in the objectId
property of the TenantDetail
object.
By verified (registered) domain name: One of the domain names that are registered for the tenant. These can be found in the verifiedDomains
property of the TenantDetail
object.
By using the myOrganization
alias: This alias is only available when using OAuth Authorization Code Grant type (3-legged) authentication; that is, when using a delegated permission scope. The alias is not case sensitive. It replaces the object ID or tenant domain in the URL. When the alias is used, Graph API derives the tenant from the claims presented in the token attached to the request.
By using the me
alias: This alias is only available when using OAuth Authorization Code Grant type (3-legged) authentication; that is, when using a delegated permission scope. The alias is not case sensitive. It replaces the object ID or tenant domain in the URL. When the alias is used, Graph API derives the user from the claims presented in the token attached to the request.
Note
You use me
alias solely to target operations against the signed-in user. For more information, see Signed-in User Operations.
Resource Path
You specify the {resource_path}
differently depending on whether you are targeting a resource collection, an individual resource, a navigation property of a resource, a function or action exposed on the tenant, or a function or action exposed on a resource.
Service metadata
Returns the service metadata document.
Note
No authentication is necessary to read the service metadata.
Resource collection
Targets a resource collection, such as users or groups in the tenant. You can use this path to read resources in the collection, and, depending on the resource type, to create a new resource in the tenant. In many cases the result set returned by a read can be further refined by the addition of query parameters to filter, order, or page the results.
Single resource
Targets a specific resource in a tenant, such as a user, organizational contact, or group. For most resources the resource_id
is the object ID. Some resources allow additional specifiers; for example, users can be also specified by user principal name (UPN). Depending on the resource, you can use this path to get the declared properties of the resource, to modify its declared properties, or to delete the resource.
Navigation property (objects)
Targets a navigation property of a specific resource, such as a user's manager or group memberships, or a group's members. You can use this path to return the object or objects referenced by the target navigation property.
Note
This form of addressing is only available for reads.
Navigation property (links)
Targets a navigation property of a specific resource, such as a user's manager or group memberships, or a group's members. You can use this form of addressing to both read and modify a navigation property. On reads, the objects referenced by the property are returned as one or more links in the response body. On writes, the objects are specified as one or more links in the request body.
Functions or actions exposed on the tenant
Targets a function or action exposed at the tenant. Functions and actions are typically invoked with a POST Request and may include a request body.
Functions or actions exposed on a resource
Targets a function or action exposed on a resource. Functions and actions are typically invoked with a POST Request and may include a request body.
Graph API Version
You use the api-version
query parameter to target a specific version of the Graph API for an operation. This parameter is required.
The value for the api-version
parameter can be one of the following:
- "beta"
- "1.6"
- "1.5"
- "2014/11/08"
- "2-13/04/05"
OData Query Parameters
In many cases when you read a collection of resources, you can filter, sort, and page the result set by attaching OData query parameters to your request.
The Graph API supports the following Odata query parameters:
- $filter
- $batch
- $expand
- $orderby
- $top
- $skiptoken and previous-page
See Supported Queries, Filters, and Paging Options for more information about supported OData query parameters and their limitations in the Graph API.
Request and Response Headers
The adjoining table shows common HTTP headers used in requests with the Graph API. It is not meant to be comprehensive.
At a minimum, we recommend you do the following for each request:
- Log an accurate time stamp of the request submission.
- Send and log the client-request-id.
- Log the HTTP response code and request-id.
Providing information in such logs will help Microsoft troubleshoot issues when you ask for help or support.
Header | Description |
---|---|
Authorization | Required. A bearer token issued by Azure Active Directory. See Authentication and Authorization in this topic for more information. |
Content-Type | Required if request body is present. The media type of the content in the request body. Use application/json. Parameters may be included with the media type. Note: application/atom+xml and application/xml (for links) are supported but are not recommended both for performance reasons and because support for XML will be deprecated in a future release. |
Content-Length | Required if request body is present. The length of the request in bytes. |
The adjoining table shows common HTTP headers returned in responses by the Graph API. It is not meant to be comprehensive.
Header | Description |
---|---|
Content-Type | The media type of the content in the response body. The default is application/json. Requests for user thumbnail photos return image/jpeg by default. |
Location | Returned in responses to POST requests that create a new resource (object) in the directory. Contains the URI of the newly created resource. |
ocp-aad-diagnostics-server-name | The identifier for the server that performed the requested operation. |
ocp-aad-session-key | The key that identifies the current session with the directory service. |
Request and Response Bodies
Request bodies for POST, PATCH, and PUT requests can be sent in JSON or XML payloads. Server responses can be returned in JSON or XML payloads. You can specify the payload in request bodies by using the Content-Type
request header and in responses by using the Accept
request header.
Important
We strongly recommend that you use JSON payloads in requests and responses with the Graph API. This is both for performance reasons and because XML will be deprecated in a future release.
Advanced Features
The preceding sections discussed the formatting of basic requests and responses with the Graph API. More advanced features may add additional query string parameters or have significantly different request and response bodies than the basic operations discussed previously in this topic.
These features include:
- Batch Processing: The Graph API supports batching. Sending requests in batches reduces round trips to the server, which reduces network overhead and helps your operations complete more quickly. For more information about batch processing with the Graph API, see Batch Processing.
- Differential Query: The Graph API supports performing differential queries. Differential query allows you to return changes to specific entities in a tenant between requests issued at different times. This feature is often used to sync a local store with changes on the tenant. For more information about differential query with the Graph API, see Differential Query.
User
Overview
With the Azure AD Graph API, you can create, read, update, and delete users. You can also query and modify a user's relationships to other directory entities. For example, you can assign the user's manager, query the user's direct reports, manage group memberships, app roles, and devices assigned to the user, and much more.
You specify the resource path differently depending on whether you are targeting the collection of all users in your tenant, an individual user, or a navigation property of a specific user.
You can use this resource path to read all users or a filtered list of users in your tenant or to create one or more new users in your tenant.
You specify the user_id
either as the object ID (GUID) or the user principal name (UPN) of the target user. You can use this resource path to get the declared properties of a user, to modify the declared properties of a user, or to delete a user.
You can use it to return the object or objects referenced by the target navigation property of the specified user. Note: This form of addressing is only available for reads.
You can use this form of addressing to both read and modify a navigation property. On reads, the objects referenced by the property are returned as one or more links in the response body. On writes, the objects are specified as one or more links in the request body.
The User entity
Represents an Azure AD user account. Inherits from DirectoryObject.
Properties
-
true
if the account is enabled; otherwise,false
. This property is required when a user is created. -
The licenses that are assigned to the user. Not nullable.
-
The plans that are assigned to the user.
-
This property is not valid for users and always returns null. Inherited from DirectoryObject. Requires version 1.5 or newer.
-
The name for the department in which the user works.
-
true
if this object is synced from an on-premises directory;false
if this object was originally synced from an on-premises directory but is no longer synced;null
if this object has never been synced from an on-premises directory (default). -
The name displayed in the address book for the user. This is usually the combination of the user's first name, middle initial and last name. This property is required when a user is created and it cannot be cleared during updates.
-
The telephone number of the user's business fax machine.
-
The given name (first name) of the user.
-
This property is used to associate an on-premises Active Directory user account to their Azure AD user object. This property must be specified when creating a new user account in the Graph if you are using a federated domain for the user’s
userPrincipalName
(UPN) property. The $ and _ characters cannot be used when specifying this property. Requires version 2013-11-08 or newer. -
The user’s job title.
-
Indicates the last time at which the object was synced with the on-premises directory; for example: "2013-02-16T03:04:54Z"
-
The SMTP address for the user, for example, "[email protected]".
-
The mail alias for the user. This property must be specified when a user is created.
-
The primary cellular telephone number for the user.
-
The unique identifier for the user. Inherited from
DirectoryObject
. Key, immutable, not nullable, unique. -
A string that identifies the object type. For users the value is always “User”. Inherited from
DirectoryObject
. -
Contains the on-premises security identifier (SID) for the user that was synchronized from on-premises to the cloud. Requires version 1.5 or newer.
-
A list of additional email addresses for the user; for example: ["[email protected]", "[email protected]"]. Not nullable, the any operator is required for filter expressions on multi-valued properties; for more information, see Supported Queries, Filters, and Paging Options.
-
Specifies password policies for the user. This value is an enumeration with one possible value being “DisableStrongPassword”, which allows weaker passwords than the default policy to be specified. “DisablePasswordExpiration” can also be specified. The two may be specified together; for example: "DisablePasswordExpiration, DisableStrongPassword".
-
Specifies the password profile for the user. The profile contains the user’s password. This property is required when a user is created. The password in the profile must satisfy minimum requirements as specified by the
passwordPolicies
property. By default, a strong password is required. For information about the constraints that must be satisfied for a strong password, see Password Policy under Change your password in the Microsoft Office 365 help pages. -
The office location in the user's place of business.
-
The postal code for the user's postal address. The postal code is specific to the user's country/region. In the United States of America, this attribute contains the ZIP code.
-
The preferred language for the user. Should follow ISO 639-1 Code; for example "en-US".
-
The plans that are provisioned for the user. Not nullable.
-
A collection of error details that are preventing this user from being provisioned successfully.
-
For example: ["SMTP: [email protected]", "smtp: [email protected]"]. Unique, not nullable, the any operator is required for filter expressions on multi-valued properties; for more information, see Supported Queries, Filters, and Paging Options.
-
Specifies the voice over IP (VOIP) session initiation protocol (SIP) address for the user. Requires version 1.5 or newer.
-
The given name (first name) of the user.
-
The state or province in the user's address.
-
The street address of the user's place of business.
-
The user's surname (family name or last name). Filterable.
-
The primary telephone number of the user's place of business.
-
A thumbnail photo to be displayed for the user. Not nullable.
-
A two letter country code (ISO standard 3166). Required for users that will be assigned licenses due to legal requirement to check for availability of services in countries. Examples include: "US", "JP", and "GB". Not nullable.
-
The user principal name (UPN) of the user. The UPN is an Internet-style login name for the user based on the Internet standard RFC 822. By convention, this should map to the user's email name. The general format is alias@domain, where domain must be present in the tenant’s collection of verified domains. This property is required when a user is created.
-
A string value that can be used to classify user types in your directory, such as “Member” and “Guest”. Requires version 2013-11-08 or newer.
Sample JSON Response
Create a user
Adds a user to the tenant. The request body contains the user to create. At a minimum, you must specify the required properties for the user. You can optionally specify any other writable properties.
Properties
-
true
if the account is enabled; otherwise,false
. -
The name to display in the address book for the user.
-
Only needs to be specified when creating a new user account if you are using a federated domain for the user's
userPrincipalName
(UPN) property. -
The mail alias for the user.
-
The password profile for the user.
-
The user principal name ([email protected]).
Returns
On success, returns the newly created User; otherwise, the response body contains error details. For more information about errors, see Error Codes and Error Handling.
HTTP Response Codes
-
Created. Indicates success. The new user is returned in the response body.
Get a user
Gets a specified user. You can use either the object ID (GUID) or the user principal name (UPN) to identify the target user.
Properties
-
The user ID. Can be the object ID (GUID) or the user principal name ([email protected]) of the target user.
-
Specifies the version of the Graph API to target. Beginning with version 1.5, the api-version string is represented in major.minor format. Prior releases were represented as date strings: '2013-11-08' and '2013-04-05'. Required.
Returns
On success, returns the User object for the specified user; otherwise, the response body contains error details. For more information about errors, see Error Codes and Error Handling.
HTTP Response Codes
-
OK. Indicates success. The user is returned in the response body.
Update a user
Update a user's properties. Specify any writable User property in the request body. Only the properties that you specify are changed.
Properties
In the request body, any writable property in the User Entity can be specified.
-
The user ID. Can be the object ID (GUID) or the user principal name ([email protected]) of the target user.
-
Specifies the version of the Graph API to target. Beginning with version 1.5, the api-version string is represented in major.minor format. Prior releases were represented as date strings: '2013-11-08' and '2013-04-05'. Required.
Returns
On success, no response body is returned; otherwise, the response body contains error details. For more information about errors, see Error Codes and Error Handling.
HTTP Response Codes
-
No Content. Indicates success. No response body is returned.
Delete a user
Get users
The signed-in user
You use can use the me
alias to target the signed-in user. This alias replaces the {tenant id}
and {resource path}
segments in the request URL. When you send a request to the Graph API with the me alias, it derives the tenant and user from the bearer token attached to the request.
You specify the URL differently depending on whether you are targeting the signed-in user or one of its navigation properties.
me
targets the signed-in user. You can use this resource path to get the declared properties of the user and to modify the declared properties of the user.-
me/{nav_property}
targets the specified navigation property of the signed-in user. You can use it to return the object or objects referenced by the target navigation property of the user.Note
This form of addressing is only available for reads.
me/$links/{nav_property}
targets the specified navigation property of the signed-in user. You can use this form of addressing to both read and modify a navigation property. On reads, the objects referenced by the property are returned as one or more links in the response body. On writes, the objects are specified as one or more links in the request body.
Group
Represents an Azure Active Directory Group. Inherited from DirectoryObject.
Contact
Represents an organizational contact. Inherits from DirectoryObject.
Organizational contacts represent users that are not in your company directory. They are mail-enabled entities and typically represent individuals who are external to your company or organization. Organizational contacts cannot be authenticated using Azure AD, nor can they be assigned licenses.
Organizational contacts can be created in your tenant through syncing with an on-premises directory using Azure AD Connect, or they can be created through one of the Exchange Online management portals or the Exchange Online PowerShell cmdlets. For more information about Azure AD Connect, see Integrating your on-premises identities with Azure Active Directory. For more information about Exchange Online management tools, see Exchange Online Setup and Administration.
You cannot create organizational contacts with the Graph API. You can, however, update and delete contacts that are not currently synced from an on-premises directory; that is, contacts for which the dirSyncEnabled property is null or false. You cannot update or delete contacts for which the dirSyncEnabled property is true.Note
Organizational contacts are directory entities, which represent external users. They should not be confused with O365 Outlook Personal contacts.
Directory Role
Domain
AlternativeSecurityId
Contains an alternative security ID associated with a device. The alternativeSecurityIds
property of the Device entity is a collection of AlternativeSecurityId
.
Properties
-
The user ID. Can be the object ID (GUID) or the user principal name ([email protected]) of the target user.
-
Specifies the version of the Graph API to target. Beginning with version 1.5, the api-version string is represented in major.minor format. Prior releases were represented as date strings: '2013-11-08' and '2013-04-05'. Required.
-
Prior releases were represented as date strings: '2013-11-08' and '2013-04-05'. Required.
AppRole
Represents an application role that may be requested by a client application calling another application or that may be used to assign an application to users or groups in a specified application role. The appRoles
property of the ServicePrincipal entity and of the Application entity is a collection of AppRole
.
Important
Requires version 1.5 or newer.
Properties
-
Specifies whether this app role definition can be assigned to users and groups by setting to “User”, or to other applications (that are accessing this application in daemon service scenarios) by setting to “Application”, or to both. Not nullable.
-
Permission help text that appears in the admin app assignment and consent experiences.
-
Display name for the permission that appears in the admin consent and app assignment experiences.
-
Unique role identifier inside the
appRoles
collection. -
When creating or updating a role definition, this must be set to
true
(which is the default). To delete a role, this must first be set tofalse
. At that point, in a subsequent call, this role may be removed. -
Specifies the value of the roles claim that the application should expect in the authentication and access tokens.