Muokkaa

Jaa


message: delta

Namespace: microsoft.graph

Important

APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.

Get a set of messages that were added, deleted, or updated in a specified folder.

A delta function call for messages in a folder is similar to a GET request, except that by appropriately applying state tokens in one or more of these calls, you can query for incremental changes in the messages in that folder. Using deltas allows you toincrementally maintain and synchronize a local store of a user's messages.

This API is available in the following national cloud deployments.

Global service US Government L4 US Government L5 (DOD) China operated by 21Vianet

Permissions

Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.

Permission type Least privileged permissions Higher privileged permissions
Delegated (work or school account) Mail.ReadBasic Mail.Read, Mail.ReadWrite
Delegated (personal Microsoft account) Mail.ReadBasic Mail.Read, Mail.ReadWrite
Application Mail.ReadBasic.All Mail.Read, Mail.ReadWrite

HTTP request

To get all changes in messages in the specified mailFolder:

GET /me/mailFolders/{id}/messages/delta
GET /users/{id}/mailFolders/{id}/messages/delta

To specifically get only created, updated, or deleted messages in the specified mailFolder:

GET /me/mailFolders/{id}/messages/delta?changeType=created
GET /users/{id}/mailFolders/{id}/messages/delta?changeType=created
GET /me/mailFolders/{id}/messages/delta?changeType=updated
GET /users/{id}/mailFolders/{id}/messages/delta?changeType=updated
GET /me/mailFolders/{id}/messages/delta?changeType=deleted
GET /users/{id}/mailFolders/{id}/messages/delta?changeType=deleted

Query parameters

Tracking changes in messages incurs a round of one or more delta function calls. If you use any OData system query option or the custom query option, changeType, you must specify it in the initial delta request. Microsoft Graph automatically encodes any specified parameters into the token portion of the @odata.nextLink or @odata.deltaLink URL provided in the response. You only need to specify any desired query parameters once upfront. In subsequent requests, simply copy and apply the @odata.nextLink or @odata.deltaLink URL from the previous response, as that URL already includes the encoded, desired parameters.

Query parameter Type Description
$deltatoken string A state token returned in the @odata.deltaLink URL of the previous delta function call for the same message collection, indicating the completion of that round of change tracking. Save and apply the entire @odata.deltaLink URL including this token in the first request of the next round of change tracking for that collection.
$skiptoken string A state token returned in the @odata.nextLink URL of the previous delta function call, indicating there are further changes to be tracked in the same message collection.
changeType string A custom query option to filter the delta response based on the type of change. Supported values are created, updated, or deleted.

OData query parameters

  • You can use a $select query parameter as in any GET request to specify only the properties your need for best performance. The id property is always returned.
  • Delta query support $select, $top, and $expand for messages.
  • There's limited support for $filter and $orderby:
    • The only supported $filter expresssions are $filter=receivedDateTime+ge+{value} or $filter=receivedDateTime+gt+{value}.
    • The only supported $orderby expression is $orderby=receivedDateTime+desc. If you don't include an $orderby expression, the return order isn't guaranteed.
  • There's no support for $search.

Request headers

Name Type Description
Authorization string Bearer {token}. Required. Learn more about authentication and authorization.
Content-Type string application/json. Required.
Prefer string odata.maxpagesize={x}. Optional.

Response

If successful, this method returns a 200 OK response code and message collection object in the response body.

Example

Request

The following example shows how to make a single delta function call, and limit the maximum number of messages in the response body to 2.

To track changes in the messages in a folder, you would make one or more delta function calls to get the set of incremental changes since the last delta query. For an example that shows a round of delta query calls, see Get incremental changes to messages in a folder.

GET https://graph.microsoft.com/beta/me/mailFolders/{id}/messages/delta

Prefer: odata.maxpagesize=2
Response

If the request is successful, the response would include a state token, which is either a skipToken (in an @odata.nextLink response header) or a deltaToken (in an @odata.deltaLink response header). Respectively, they indicate whether you should continue with the round or you finished getting all the changes for that round.

The following response shows a skipToken in an @odata.nextLink response header.

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

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

{
  "@odata.nextLink":"https://graph.microsoft.com/beta/me/mailFolders/{id}/messages/delta?$skiptoken={_skipToken_}",
  "value": [
    {
      "receivedDateTime": "datetime-value",
      "sentDateTime": "datetime-value",
      "hasAttachments": true,
      "internetMessageId": "internetMessageId-value",
      "subject": "subject-value",
      "body": {
        "contentType": "contentType-value",
        "content": "content-value"
      }
    }
  ]
}