Create subscription - Microsoft Graph v1.0 (2024)

  • Article

Namespace: microsoft.graph

Subscribes a listener application to receive change notifications when the requested type of changes occur to the specified resource in Microsoft Graph.

To identify the resources for which you can create subscriptions and the limitations on subscriptions, see Set up notifications for changes in resource data: Supported resources.

Some resources support rich notifications, that is, notifications that include resource data. For more information about these resources, see Set up change notifications that include resource data: Supported resources.

This API is available in the following national cloud deployments.

Global serviceUS Government L4US Government L5 (DOD)China operated by 21Vianet

Permissions

Creating a subscription requires read scope to the resource. For example, to get change notifications on messages, your app needs the Mail.Read permission.

Depending on the resource and the permission type (delegated or application) requested, the permission specified in the following table is the least privileged required to call this API. To learn more, including taking caution before choosing the permissions, search for the following permissions in Permissions.

Supported resourceDelegated (work or school account)Delegated (personal Microsoft account)Application
callRecord (/communications/callRecords)Not supportedNot supportedCallRecords.Read.All
callRecording
communications/onlineMeetings/getAllRecordings
All recordings in an organization.
Not supported.Not supported.OnlineMeetingRecording.Read.All
callRecording
communications/onlineMeetings/{onlineMeetingId}/recordings
All recordings for a specific meeting.
OnlineMeetingRecording.Read.AllNot supported.OnlineMeetingRecording.Read.All
callRecording
users/{userId}/onlineMeetings/getAllRecordings
A call recording that becomes available in a meeting organized by a specific user.
OnlineMeetingRecording.Read.AllNot supported.OnlineMeetingRecording.Read.All
callTranscript
communications/onlineMeetings/getAllTranscripts
All transcripts in an organization.
Not supported.Not supported.OnlineMeetingTranscript.Read.All
callTranscript
communications/onlineMeetings/{onlineMeetingId}/transcripts
All transcripts for a specific meeting.
OnlineMeetingTranscript.Read.AllNot supported.OnlineMeetingTranscript.Read.All
callTranscript
users/{userId}/onlineMeetings/getAllTranscripts
A call transcript that becomes available in a meeting organized by a specific user.
OnlineMeetingTranscript.Read.AllNot supported.OnlineMeetingTranscript.Read.All
channel (/teams/getAllChannels – all channels in an organization)Not supportedNot supportedChannel.ReadBasic.All, ChannelSettings.Read.All
channel (/teams/{id}/channels)Channel.ReadBasic.All, ChannelSettings.Read.AllNot supportedChannel.ReadBasic.All, ChannelSettings.Read.All
chat (/chats – all chats in an organization)Not supportedNot supportedChat.ReadBasic.All, Chat.Read.All, Chat.ReadWrite.All
chat (/chats/{id})Chat.ReadBasic, Chat.Read, Chat.ReadWriteNot supportedChatSettings.Read.Chat*, ChatSettings.ReadWrite.Chat*, Chat.Manage.Chat*, Chat.ReadBasic.All, Chat.Read.All, Chat.ReadWrite.All
chat
/appCatalogs/teamsApps/{id}/installedToChats
All chats in an organization where a particular Teams app is installed.
Not supportedNot supportedChat.ReadBasic.WhereInstalled, Chat.Read.WhereInstalled, Chat.ReadWrite.WhereInstalled
chatMessage (/teams/{id}/channels/{id}/messages)ChannelMessage.Read.AllNot supportedChannelMessage.Read.Group*, ChannelMessage.Read.All
chatMessage (/teams/getAllMessages -- all channel messages in organization)Not supportedNot supportedChannelMessage.Read.All
chatMessage (/chats/{id}/messages)Chat.Read, Chat.ReadWriteNot supportedChat.Read.All
chatMessage (/chats/getAllMessages -- all chat messages in organization)Not supportedNot supportedChat.Read.All
chatMessage (/users/{id}/chats/getAllMessages -- chat messages for all chats a particular user is part of)Chat.Read, Chat.ReadWriteNot supportedChat.Read.All, Chat.ReadWrite.All
chatMessage
/appCatalogs/teamsApps/{id}/installedToChats/getAllMessages
Chat messages for all chats in an organization where a particular Teams app is installed.
Not supportedNot supportedChat.Read.WhereInstalled, Chat.ReadWrite.WhereInstalled
contactContacts.ReadContacts.ReadContacts.Read
conversationMember (/chats/getAllMembers)Not supportedNot supportedChatMember.Read.All, ChatMember.ReadWrite.All, Chat.ReadBasic.All, Chat.Read.All, Chat.ReadWrite.All
conversationMember (/chats/{id}/members)ChatMember.Read, ChatMember.ReadWrite, Chat.ReadBasic, Chat.Read, Chat.ReadWriteNot supportedChatMember.Read.Chat*, Chat.Manage.Chat*, ChatMember.Read.All, ChatMember.ReadWrite.All, Chat.ReadBasic.All, Chat.Read.All, Chat.ReadWrite.All
conversationMember
/appCatalogs/teamsApps/{id}/installedToChats/getAllMembers
Chat members for all chats in an organization where a particular Teams app is installed.
Not supported.Not supported.ChatMember.Read.WhereInstalled, ChatMember.ReadWrite.WhereInstalled, Chat.ReadBasic.WhereInstalled, Chat.Read.WhereInstalled, Chat.ReadWrite.WhereInstalled
conversationMember (/teams/{id}/members)TeamMember.Read.AllNot supportedTeamMember.Read.All
conversationMember (/teams/{id}/channels/getAllMembers)Not supportedNot supportedChannelMember.Read.All
driveItem (user's personal OneDrive)Not supportedFiles.ReadWriteNot supported
driveItem (OneDrive for Business)Files.ReadWrite.AllNot supportedFiles.ReadWrite.All
eventCalendars.ReadCalendars.ReadCalendars.Read
groupGroup.Read.AllNot supportedGroup.Read.All
group conversationGroup.Read.AllNot supportedNot supported
listSites.ReadWrite.AllNot supportedSites.ReadWrite.All
messageMail.ReadBasic, Mail.ReadMail.ReadBasic, Mail.ReadMail.Read
presencePresence.Read.AllNot supportedNot supported
printerNot supportedNot supportedPrinter.Read.All, Printer.ReadWrite.All
printTaskDefinitionNot supportedNot supportedPrintTaskDefinition.ReadWrite.All
security alertSecurityEvents.ReadWrite.AllNot supportedSecurityEvents.ReadWrite.All
team (/teams – all teams in an organization)Not supportedNot supportedTeam.ReadBasic.All, TeamSettings.Read.All
team (/teams/{id})Team.ReadBasic.All, TeamSettings.Read.AllNot supportedTeam.ReadBasic.All, TeamSettings.Read.All
todoTaskTasks.ReadWriteTasks.ReadWriteNot supported
userUser.Read.AllUser.Read.AllUser.Read.All
virtualEventWebinarVirtualEvent.ReadNot supported.VirtualEvent.Read.All

We recommend that you use the permissions as documented in the previous table. Due to security restrictions, Microsoft Graph subscriptions don't support write access permissions when only read access permissions are needed.

Note: Permissions marked with * use resource-specific consent.

chatMessage

chatMessage subscriptions can be specified to include resource data. If specified to include resource data (includeResourceData set to true), encryption is required. The subscription creation fails if an encryptionCertificate isn't specified for such subscriptions.

You must use the Prefer: include-unknown-enum-members request header to get the following values in chatMessage messageType evolvable enum: systemEventMessage for /teams/{id}/channels/{id}/messages and /chats/{id}/messages resource.

Note

/teams/getAllMessages, /chats/getAllMessages, /me/chats/getAllMessages, /users/{id}/chats/getAllMessages, and /appCatalogs/teamsApps/{id}/installedToChats/getAllMessagesare metered APIs; payment models and licensing requirements may apply./teams/getAllMessages and /chats/getAllMessages support both model=A and model=B payment models,/me/chats/getAllMessages, /users/{id}/chats/getAllMessages, and /appCatalogs/teamsApps/{id}/installedToChats/getAllMessages support only model=B.If you don't specify a payment model in your query, the default evaluation mode will be used.

Note

To add or change a payment model for a subscribed resource of a change notification, you must create a new change notification subscription with the new payment model; updating an existing change notification does not work.

conversationMember

conversationMember subscriptions can be specified to include resource data. If specified to include resource data (includeResourceData set to true), encryption is required. The subscription creation fails if an encryptionCertificate isn't specified.

Note

/teams/getAllMembers, /chats/getAllMembers, and /appCatalogs/teamsApps/{id}/installedToChats/getAllMembers are metered APIs; payment models and licensing requirements may apply./teams/getAllMembers and /chats/getAllMembers support both model=A and model=B payment models. /appCatalogs/teamsApps/{id}/installedToChats/getAllMembers supports only model=B.If you don't specify a payment model in your query, the default evaluation mode will be used.

Note

To add or change a payment model for a subscribed resource of a change notification, you must create a new change notification subscription with the new payment model; updating an existing change notification does not work.

team, channel, and chat

team, channel, and chat subscriptions can be specified to include resource data. If specified to include resource data (includeResourceData set to true), encryption is required. The subscription creation fails if an encryptionCertificate isn't specified.

Note

/appCatalogs/teamsApps/{id}/installedToChats has licensing and payment requirements, specifically supporting only model=B.If no model is specified, evaluation mode will be used.

Note

To add or change a payment model for a subscribed resource of a change notification, you must create a new change notification subscription with the new payment model; updating an existing change notification does not work.

Request example

Specify the model query parameter in the resource property in the request body.

POST https://graph.microsoft.com/v1.0/subscriptionsContent-type: application/json{ "changeType": "created", "notificationUrl": "https://webhook.azurewebsites.net/api/send/myNotifyClient", "resource": "chats/getAllMessages?model=A", "expirationDateTime":"2016-11-20T18:23:45.9356913Z", "clientState": "secretClientValue", "latestSupportedTlsVersion": "v1_2"}

driveItem

Additional limitations apply for subscriptions on OneDrive items. The limitations apply to creating as well as managing (getting, updating, and deleting) subscriptions.

On a personal OneDrive, you can subscribe to the root folder or any subfolder in that drive. On OneDrive for Business, you can subscribe to only the root folder. Change notifications are sent for the requested types of changes on the subscribed folder, or any file, folder, or other driveItem instances in its hierarchy. You can't subscribe to drive or driveItem instances that aren't folders, such as individual files.

OneDrive for Business and SharePoint support sending your application notifications of security events that occur on a driveItem. To subscribe to these events, add the prefer:includesecuritywebhooks header to your request to create a subscription. After the subscription is created, you will receive notifications when the permissions on an item change. This header is applicable to SharePoint and OneDrive for Business but not consumer OneDrive accounts.

contact, event, and message

You can subscribe to changes in Outlook contact, event, or message resources.

Creating and managing (getting, updating, and deleting) a subscription requires a read scope to the resource. For example, to get change notifications on messages, your app needs the Mail.Read permission. Outlook change notifications support delegated and application permission scopes. Note the following limitations:

  • Delegated permission supports subscribing to items in folders in only the signed-in user's mailbox. For example, you can't use the delegated permission Calendars.Read to subscribe to events in another user’s mailbox.

  • To subscribe to change notifications of Outlook contacts, events, or messages in shared or delegated folders:

    • Use the corresponding application permission to subscribe to changes of items in a folder or mailbox of any user in the tenant.
    • Don't use the Outlook sharing permissions (Contacts.Read.Shared, Calendars.Read.Shared, Mail.Read.Shared, and their read/write counterparts), as they do not support subscribing to change notifications on items in shared or delegated folders.

presence

Subscriptions on presence require any resource data included in a change notification to be encrypted. Always specify the encryptionCertificate parameter when creating a subscription to avoid failure. See more information about setting up change notifications to include resource data.

virtualEventWebinar

Subscriptions on virtual events support only basic notifications and are limited to a few entities of a virtual event. For more information about the supported subscription types, see Get change notifications for Microsoft Teams virtual event updates.

HTTP request

POST /subscriptions

Request headers

NameTypeDescription
AuthorizationstringBearer {token}. Required.

Request body

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

Response

If successful, this method returns 201 Created response code and a subscription object in the response body.For details about how errors are returned, see Error responses.

Example

Request

The following example shows a request to send a change notification when the user receives a new mail.

  • HTTP
  • C#
  • CLI
  • Go
  • Java
  • JavaScript
  • PHP
  • PowerShell
  • Python
POST https://graph.microsoft.com/v1.0/subscriptionsContent-type: application/json{ "changeType": "created", "notificationUrl": "https://webhook.azurewebsites.net/api/send/myNotifyClient", "resource": "me/mailFolders('Inbox')/messages", "expirationDateTime":"2016-11-20T18:23:45.9356913Z", "clientState": "secretClientValue", "latestSupportedTlsVersion": "v1_2"}

In the request body, supply a JSON representation of the subscription object.The clientState and latestSupportedTlsVersion fields are optional.

Duplicate subscription behavior

Duplicate subscriptions aren't allowed. When a subscription request contains the same values for changeType and resource that an existing subscription contains, the request fails with an HTTP error code 409 Conflict, and the error message Subscription Id <> already exists for the requested combination.

Resources examples

The following are valid values for the resource property of the subscription:

Resource typeExamples
Call recordscommunications/callRecords
callRecordingcommunications/onlineMeetings/getAllRecordings, communications/onlineMeetings/{onlineMeetingId}/recordings, users/{userId}/onlineMeetings/getAllRecordings
callTranscriptcommunications/onlineMeetings/getAllTranscripts, communications/onlineMeetings/{onlineMeetingId}/transcripts, users/{userId}/onlineMeetings/getAllTranscripts
Chat messagechats/{id}/messages, chats/getAllMessages, teams/{id}/channels/{id}/messages, teams/getAllMessages
Contactsme/contacts
Conversationsgroups('{id}')/conversations
Drivesme/drive/root
Eventsme/events
Groupsgroups
Listsites/{site-id}/lists/{list-id}
Mailme/mailfolders('inbox')/messages, me/messages
Presence/communications/presences/{id} (single user), /communications/presences?$filter=id in ('{id}','{id}',…) (multiple users)
printerprint/printers/{id}/jobs
PrintTaskDefinitionprint/taskDefinitions/{id}/tasks
Security alertsecurity/alerts?$filter=status eq 'New'
todoTask/me/todo/lists/{todoTaskListId}/tasks
Usersusers

Note: Any path starting with me can also be used with users/{id} instead of me to target a specific user instead of the current user.

Response

The following example shows the response.

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

HTTP/1.1 201 CreatedContent-type: application/json{ "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#subscriptions/$entity", "id": "7f105c7d-2dc5-4530-97cd-4e7ae6534c07", "resource": "me/mailFolders('Inbox')/messages", "applicationId": "24d3b144-21ae-4080-943f-7067b395b913", "changeType": "created", "clientState": "secretClientValue", "notificationUrl": "https://webhook.azurewebsites.net/api/send/myNotifyClient", "expirationDateTime": "2016-11-20T18:23:45.9356913Z", "creatorId": "8ee44408-0679-472c-bc2a-692812af3437", "latestSupportedTlsVersion": "v1_2", "notificationContentType": "application/json"}

Notification endpoint validation

The subscription notification endpoint (specified in the notificationUrl property) must be capable of responding to a validation request as described in Set up notifications for changes in user data. If validation fails, the request to create the subscription returns a 400 Bad Request error.

Create subscription - Microsoft Graph v1.0 (2024)
Top Articles
Latest Posts
Article information

Author: Corie Satterfield

Last Updated:

Views: 5970

Rating: 4.1 / 5 (42 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Corie Satterfield

Birthday: 1992-08-19

Address: 850 Benjamin Bridge, Dickinsonchester, CO 68572-0542

Phone: +26813599986666

Job: Sales Manager

Hobby: Table tennis, Soapmaking, Flower arranging, amateur radio, Rock climbing, scrapbook, Horseback riding

Introduction: My name is Corie Satterfield, I am a fancy, perfect, spotless, quaint, fantastic, funny, lucky person who loves writing and wants to share my knowledge and understanding with you.