JMAP N. Jenkins
Internet-Draft FastMail
Intended status: Standards Track March 5, 2018
Expires: September 6, 2018

JSON Meta Application Protocol


This document specifies a protocol for synchronising JSON-based data objects efficiently, with support for push and out-of-band binary data upload/download.

Status of This Memo

This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.

Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at

Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."

This Internet-Draft will expire on September 6, 2018.

Copyright Notice

Copyright (c) 2018 IETF Trust and the persons identified as the document authors. All rights reserved.

This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents ( in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.

Table of Contents

1. Introduction

JMAP is a generic protocol for synchronising data, such as mail, calendars or contacts, between a client and a server. It is optimised for mobile and web environments, and aims to provide a consistent interface to different data types.

This specification is for the generic mechanism of data synchronisation. Further specifications define the data models for different data types that may be synchronised via JMAP.

JMAP is designed to make efficient use of limited network resources. Multiple API calls may be batched in a single request to the server, reducing round trips and improving battery life on mobile devices. Push connections remove the need for polling, and an efficient delta update mechanism ensures a minimum of data is transferred.

JMAP is designed to be horizontally scalable to a very large number of users. This is facilitated by the separate end points for users after login, the separation of binary and structured data, and a shared data model that does not allow data dependencies between accounts.

1.1. Notational conventions

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC2119].

The underlying format used for this specification is JSON. Consequently, the terms "object" and "array" as well as the four primitive types (strings, numbers, booleans, and null) are to be interpreted as described in Section 1 of [RFC7159]. Unless otherwise noted, all the property names and values are case sensitive.

Some examples in this document contain "partial" JSON documents used for illustrative purposes. In these examples, three periods "..." are used to indicate a portion of the document that has been removed for compactness.

Types signatures are given for all JSON objects in this document. The following conventions are used:

1.2. The Number datatype

The JSON datatypes are limited to those found in JavaScript. A Number in JavaScript is represented as a signed double (64-bit floating point). However, except where explicitly specified, all numbers used in this API are unsigned integers <= 2^53 (the maximum integer that may be reliably stored in a double).

1.3. The Date datatypes

Where Date is given as a type, it means a string in [RFC3339] date-time format. To ensure a normalised form, the time-secfrac MUST always be omitted and any letters in the string (e.g. "T" and "Z") MUST be upper-case. For example, "2014-10-30T14:12:00+08:00".

Where UTCDate is given as a type, it means a Date where the time-offset component MUST be Z (i.e. it must be in UTC time). For example, "2014-10-30T06:12:00Z".

1.4. JSON as the data encoding format

JSON is a text-based data interchange format as specified in [RFC7159]. The I-JSON format defined in [RFC7493] is a strict subset of this, adding restrictions to avoid potentially confusing scenarios (for example, it mandates that an object MUST NOT have two properties with the same key).

All data sent from the client to the server or from the server to the client (except binary file upload/download) MUST be valid I-JSON according to the RFC, and is therefore case-sensitive and encoded in UTF-8 ([RFC3629]).

1.5. Terminology

1.5.1. User

A user represents a set of permissions relating to what data can be seen.

1.5.2. Accounts

An account is a collection of data. A single account may contain an arbitrary set of data types, for example a collection of mail, contacts and calendars. Most operations in JMAP are isolated to a single account; there are a few explicit operations to copy data between them. Certain properties are guaranteed for data within the same account, for example uniqueness of ids within a type in that account.

An account is not the same as a user, although it is common for the primary account to directly belong to the user. For example, you may have an account that contains data for a group or business, to which multiple users have access. Users may also have access to accounts belonging to another user if that user is sharing some of their data. A single set of credentials may provide access to data in multiple accounts.

1.5.3. Data types and records

JMAP provides a uniform interface for creating, retrieving, updating and deleting various types of objects. A data type is a collection of named, typed properties, just like the schema for a database table. Each instance of a data type is called a record.

1.6. Ids

All record ids are assigned by the server, and are immutable. They MUST be unique among all records of the same type within the same account. Ids may clash across accounts, or for two records of different types within the same account.

Ids are always Strings. An id MUST be a valid UTF-8 string of at least 1 character in length and maximum 256 octets in size, but MUST NOT start with the # character, as this is reserved for doing back references during object creation (see the /set description).

1.7. The JMAP API model

JMAP uses HTTP [RFC7230] to expose API, Push, Upload and Download resources. Implementations MUST support HTTP/1.1, and MAY support later versions. Support for common HTTP mechanisms such as redirection and caching are assumed.

All HTTP requests MUST be authenticated. Servers MUST conform with the [RFC7235] HTTP Authentication framework to reject requests that fail authentication and inform the client of available authentication schemes.

Clients SHOULD understand and be able to handle standard HTTP status codes appropriately.

An authenticated client can fetch the JMAP Session object with details about the data and capabilities the server can provide as shown in section 2. The client may then exchange data with the server in the following ways:

  1. The client may make an API request to the server to get or set structured data. This request consists of an ordered series of method calls. These are processed by the server, which then returns an ordered series of responses. This is described in sections 3 and 4.
  2. The client may download or upload binary files from/to the server. This is detailed in section 5.
  3. The client may connect to a push channel on the server, to be notified when data has changed. This is explained in section 6.

2. The JMAP Session resource

To communicate with a JMAP server you need two things to start:

  1. The URL for the JMAP Session resource. This may be requested directly from the user, or discovered automatically based on a username domain (see Service Autodiscovery section below).
  2. Credentials to authenticate with. How to obtain credentials is out of scope for this specification.

An authenticated GET request to the JMAP Session resource MUST return the details about the data and capabilities the server can provide to the client given those credentials.

The response to a successful request is a JSON-encoded JMAP Session object. It has the following properties:

To ensure future compatibility, other properties MAY be included on the JMAP Session object. Clients MUST ignore any properties they are not expecting.

2.1. Service Autodiscovery

There are two standardised autodiscovery methods in use for internet protocols:

A JMAP-supporting host for the domain SHOULD publish a SRV record which gives a hostname and port (usually port 443). The JMAP Session resource is then https://${hostname}[:${port}]/.well-known/jmap (following any redirects).

If the client has a username in the form of an email address, it MAY use the domain portion of this to attempt autodiscovery of the JMAP server.

3. Structured data exchange

The client may make an API request to the server to get or set structured data. This request consists of an ordered series of method calls. These are processed by the server, which then returns an ordered series of responses.

3.1. Making an API request

To make an API request, the client makes an authenticated POST request to the API resource, the location of which may be found on the JMAP Session object.

The request MUST consist of a single JSON Request object. If successful, the response MUST also be of type application/json and consist of a single Response object.

3.2. The Request object

A Request object has the following properties:

Future specifications MAY add further properties to the Request object to extend the semantics. To ensure forwards compatability, a server MUST ignore any other properties it does not understand on the JMAP request object.

3.2.1. Example request

  "using": [ "", "" ],
  "methodCalls": [
    ["method1", {"arg1": "arg1data", "arg2": "arg2data"}, "#1"],
    ["method2", {"arg1": "arg1data"}, "#2"],
    ["method3", {}, "#3"]

3.3. Vendor-specific extensions

Individual services will have custom features they wish to expose over JMAP. This may take the form of extra datatypes and/or methods not in the spec, or extra arguments to JMAP methods, or extra properties on existing data types (which may also appear in arguments to methods that take property names).

The server can advertise custom extensions it supports by including the identifiers in the capabilities object. Identifiers for vendor extensions MUST be a URL belonging to a domain owned by the vendor, to avoid conflict. The URL SHOULD resolve to documentation for the changes the extension makes.

To ensure compatibility with clients that don't know about a specific custom extension, and for compatibility with future versions of JMAP, to use an extension the client MUST opt in by passing the appropriate capability identifier in the using array of the Request object. The server MUST only follow the specifications that are opted-into and behave as though it does not implement anything else when processing a request.

3.4. The Response object

A Response object has the following properties:

Unless otherwise specified, if the method call completed successfully its response name is the same as the method name in the request.

3.4.1. Example response:

  "methodResponses": [
    ["method1", {"arg1": 3, "arg2": "foo"}, "#1"],
    ["method2", {"isBlah": true}, "#2"],
    ["anotherResponseFromMethod2", {
      "data": 10,
      "yetmoredata": "Hello"
    }, "#2"],
    ["error", {"type":"unknownMethod"}, "#3"]

3.5. Omitting arguments

An argument to a method may be specified to have a default value. If omitted by the client, the server MUST treat the method call the same as if the default value had been specified. Similarly, the server MAY omit any argument in a response which has the default value.

Unless otherwise specified in a method description, null is the default value for any argument in a request or response where this is allowed by the type signature. Other arguments may only be omitted if an explicit default value is defined in the method description.

3.6. Errors

3.6.1. Request-level errors

If the data sent as an API request is not valid JSON or does not match the structure above, or includes a capability that the server does not support in the "using" property of the request, a 400 Bad Request error will be returned at the HTTP level. The body of the response SHOULD include a short description of the problem to help client developers debug the issue.

3.6.2. Method-level errors

If a method encounters an error, the appropriate error response MUST be inserted at the current point in the methodResponses array and, unless otherwise specified, further processing MUST NOT happen within that method call.

Any further method calls in the request MUST then be processed as normal.

An error response looks like this:

["error", {
  type: "unknownMethod"
}, "client-id"]

The response name is error, and it MUST have a type property. Other properties may be present with further information; these are detailed in the error type descriptions where appropriate.

With the exception of serverError, the externally-visible state of the server MUST NOT have changed if an error is returned at the method level.

The following error types are defined which may be returned for any method call where appropriate:

serverError: An unexpected or unknown error occured during the processing of the call. The state of the server after such an error is undefined.

unknownMethod: The server does not recognise this method name.

invalidArguments: One of the arguments is of the wrong type or otherwise invalid, or a required argument is missing. A description property MAY be present to help debug with an explanation of what the problem was. This is a non-localised string, and is not intended to be shown directly to end users.

forbidden: The method and arguments are valid, but executing the method would violate an ACL or other permissions policy.

timedOut: The method failed to execute because it timed out waiting for a lock, or was taking too much compute time.

accountNotFound: An accountId was included with the method call that does not correspond to a valid account.

accountNotSupportedByMethod: An accountId given corresponds to a valid account, but the account does not support this data type.

accountReadOnly: This method call would modify state in an account that has isReadOnly == true.

Further possible errors for a particular method are specified in the method descriptions.

Further general errors MAY be defined in future RFCs. Should a client receive an error type it does not understand, it MUST treat it the same as the serverError type.

3.7. References to previous method results

To allow clients to make more efficient use of the network and avoid round trips, an argument to one method can be taken from the result of a previous method call.

To do this, the client prefixes the argument name with "#". The value is a ResultReference object as described below. When processing a method call, the server MUST first check the arguments object for any names beginning with "#". If found, the back reference should be resolved and the value used as the "real" argument. The method is then processed as normal. If any back reference fails to resolve, the whole method MUST be rejected with a resultReference error. If an argument object contains the same argument name in normal and referenced form (e.g. foo and #foo), the method MUST return an invalidArguments error.

A ResultReference object has the following properties:

To resolve:

  1. Find the first response with a client id identical to the resultOf property of the ResultReference in the methodResponses array from previously processed method calls in the same request. If none, evaluation fails.
  2. If the response name is not identical to the name property of the ResultReference, evaluation fails.
  3. Apply the path to the arguments object of the response (the second item in the response array) following the [RFC6901] JSON pointer algorithm, except with the following addition in Section 4 (Evaluation):

If the currently referenced value is a JSON array, the reference token may be exactly the single character *, making the new referenced value the result of applying the rest of the JSON pointer tokens to every item in the array and returning the results in the same order in a new array. If the result of applying the rest of the pointer tokens to a value was itself an array, its items should be included individually in the output rather than including the array itself (i.e. the result is flattened from an array of arrays to a single array).

As a simple example, suppose we have the following API request methodCalls:

[[ "Foo/changes", {
    "sinceState": "abcdef"
}, "t0" ],
[ "Foo/get", {
    "#ids": {
        "resultOf": "t0",
        "name": "Foo/changes",
        "path": "/changed"
}, "t1" ]]

After executing the first method call the methodResponses array is:

[[ "Foo/changes", {
    "accountId": "1",
    "oldState": "abcdef",
    "newState": "123456",
    "hasMoreChanges": false,
    "changed": [ "f1", "f4" ],
    "destroyed": []
}, "t0" ]]

So to execute the Foo/get call, we look through the arguments and find there is one with a # prefix. To resolve this, we apply the algorithm above:

  1. Find the first response with client id "t0". The Foo/changes response fulfils this criterion.
  2. Check the response name is the same as in the result reference. It is, so this is fine.
  3. Apply the path as a JSON pointer to the arguments object. This simply selects the "changed" property, so the result of evaluating is: [ "f1", "f4" ]

The JMAP server now continues to process the Foo/get call as though the arguments were:

    "ids": [ "f1", "f4" ]

Now a more complicated example using the JMAP Mail data model: fetch the "from"/"date"/"subject" for every email in the first 10 threads in the Inbox (sorted newest first):

[[ "Email/query", {
  "filter": { inMailbox: "id_of_inbox" },
  "sort": [{ property: "receivedAt", isAscending: false }],
  "collapseThreads": true,
  "position": 0,
  "limit": 10
}, "t0" ],
[ "Email/get", {
  "#ids": {
    "resultOf": "t0",
    "name": "Email/query",
    "path": "/ids"
  "properties": [ "threadId" ]
}, "t1" ],
[ "Thread/get", {
  "#ids": {
    "resultOf": "t1",
    "name": "Email/get",
    "path": "/list/*/threadId"
}, "t2" ],
[ "Email/get", {
  "#ids": {
    "resultOf": "t2",
    "name": "Thread/get",
    "path": "/list/*/emailIds"
  "properties": [ "from", "receivedAt", "subject" ]
}, "t3" ]]

After executing the first 3 method calls the methodResponses array might be:

[[ "Email/query", {
    "accountId": "1",
    "filter": { inMailbox: "id_of_inbox" },
    "sort": [{ property: "receivedAt", isAscending: false }],
    "collapseThreads": true,
    "state": "abcdefg",
    "canCalculateChanges": true,
    "position": 0,
    "total": 101,
    "ids": [ "msg1023", "msg223", "msg110", "msg93", "msg91", "msg38", "msg36", "msg33", "msg11", "msg1" ]
}, "t0" ],
[ "Email/get", {
    "accountId": "1",
    "state": "123456",
    "list": [{
        "id": "msg1023",
        "threadId": "trd194",
    }, {
        "id": "msg223",
        "threadId": "trd114"
    "notFound": null
}, "t1" ],
[ "Thread/get", {
    "accountId": "1",
    "state": "123456",
    "list": [{
        "id: "trd194",
        "emailIds": [ "msg1020", "msg1021", "msg1023" ]
    }, {
        "id: "trd114",
        "emailIds": [ "msg201", "msg223" ]
    "notFound": null
}, "t2" ]]

So to execute the final Email/get call, we look through the arguments and find there is one with a # prefix. To resolve this, we apply the algorithm:

i) `emailIds`: get the array of email ids
ii) Concatenate these into a single array of all the ids in the result.

  1. Find the first response with client id "t2". The "Thread/get" response fulfils this criterion.
  2. "Thread/get" is the name specified in the result reference, so this is fine.
  3. Apply the path as a JSON pointer to the arguments object. Token-by-token: a) list: get the array of thread objects b) *: for each of the items in the array:

The JMAP server now continues to process the Email/get call as though the arguments were:

    "ids": [ "msg1020", "msg1021", "msg1023", "msg201", "msg223", etc... ],
    "properties": [ "from", "receivedAt", "subject" ]

3.8. Security

As always, the server must be strict about data received from the client. Arguments need to be checked for validity; a malicious user could attempt to find an exploit through the API. In case of invalid arguments (unknown/insufficient/wrong type for data etc.) the method MUST return an invalidArguments error and terminate.

3.9. Concurrency

Each individual method call within a request MUST be serializable; concurrent execution of methods MUST produce the same effect as running them one at a time in some order.

This means that the observable ordering may interleave method calls from different concurrent API requests, such that the data on the server may change between two method calls within a single API request.

4. Standard methods and naming convention

JMAP provides a uniform interface for creating, retrieving, updating and deleting objects of a particular type. For a Foo data type, records of that type would be fetched via a Foo/get call and modified via a Foo/set call. Delta updates may be fetched via a Foo/changes call. These methods all follow a standard format as described below.

4.1. /get

Objects of type Foo are fetched via a call to Foo/get.

It takes the following arguments:

The response has the following arguments:

The following additional error may be returned instead of the Foo/get response:

requestTooLarge: The number of ids requested by the client exceeds the maximum number the server is willing to process in a single method call.

4.2. /changes

When the state of the set of Foo records changes on the server (whether due to creation, updates or deletion), the state property of the Foo/get response will change. The Foo/changes method allows a client to efficiently update the state of its Foo cache to match the new state on the server. It takes the following arguments:

The response has the following arguments:

If a maxChanges is supplied, or set automatically by the server, the server MUST ensure the number of ids returned across changed and destroyed does not exceed this limit. If there are more changes than this between the client's state and the current server state, the update returned SHOULD generate an update to take the client to an intermediate state, from which the client can continue to call Foo/changes until it is fully up to date. If it is unable to calculate an intermediate state, it MUST return a cannotCalculateChanges error response instead.

If a Foo record has been modified AND destroyed since the oldState, the server SHOULD just return the id in the destroyed list, but MAY return it in the changed list as well. If a Foo record has been created AND destroyed since the oldState, the server SHOULD remove the id from the response entirely, but MAY include it in the destroyed list.

The following additional errors may be returned instead of the Foo/changes response:

cannotCalculateChanges: The server cannot calculate the changes from the state string given by the client. Usually due to the client's state being too old, or the server being unable to produce an update to an intermediate state when there are too many updates. The client MUST invalidate its Foo cache.

Maintaining state to allow calculation of Foo/changes can be expensive for the server, but always returning cannotCalculateChanges severely increases network traffic and resource usage for the client. To allow efficient sync, servers SHOULD be able to calculate changes from any state string that was given to a client within the last 30 days (but of course may support calculating updates from states older than this).

4.3. /set

Modifying the state of Foo objects on the server is done via the Foo/set method. This encompasses creating, updating and destroying Foo records. This allows the server to sort out ordering and dependencies that may exist if doing multiple operations at once (for example to ensure there is always a minimum number of a certain record type).

The Foo/set method takes the following arguments:

Each creation, modification or destruction of an object is considered an atomic unit. It is permissible for the server to commit changes to some objects but not others, however it is not permissible to only commit part of an update to a single record (e.g. update a name property but not a count property, if both are supplied in the update object).

The final state MUST be valid after the Foo/set is finished, however the server may have to transition through invalid intermediate states (not exposed to the client) while processing the individual create/update/destroy requests. For example, suppose there is a "name" property that must be unique. A single method call could rename an object A => B, and simultaneously rename another object B => A. If the final state is valid, this is allowed. Otherwise, each creation, modification or destruction of an object should be processed sequentially and accepted/rejected based on the current server state.

If a create, update or destroy is rejected, the appropriate error MUST be added to the notCreated/notUpdated/notDestroyed property of the response and the server MUST continue to the next create/update/destroy. It does not terminate the method.

If an id given cannot be found, the update or destroy MUST be rejected with a notFound set error.

The server MAY skip an update (rejecting it with a willDestroy SetError) if that object is destroyed in the same /set request.

Some record objects may hold references to others (foreign keys). When records are created or modified, they may reference other records being created in the same API request by using the creation id prefixed with a #. The order of the method calls in the request by the client MUST be such that the record being referenced is created in the same or an earlier call. The server thus never has to look ahead. Instead, while processing a request (a series of method calls), the server MUST keep a simple map for the duration of the request of creation id to record id for each newly created record, so it can substitute in the correct value if necessary in later method calls.

Creation ids are scoped by type; a separate creation id -> id map MUST be kept for each type for the duration of the request. Foreign key references are always for a particular record type, so use of the same creation key in two different types cannot cause any ambiguity. Creation ids sent by the client SHOULD be unique within the single API request for a particular data type. If a creation id is reused for the same type, the server MUST map the creation id to the most recently created item with that id.

The response has the following arguments:

A SetError object has the following properties:

The following SetError types are defined and may be returned for set operations on any record type where appropriate:

Other possible SetError types MAY be given in specific method descriptions. Other properties MAY also be present on the SetError object, as described in the relevant methods.

The following additional errors may be returned instead of the Foo/set response:

requestTooLarge: The total number of objects to create, update or destroy exceeds the maximum number the server is willing to process in a single method call.

stateMismatch: An ifInState argument was supplied and it does not match the current state.

4.4. /query

For data sets where the total amount of data is expected to be very small, clients can just fetch the complete set of data and then do any sorting/filtering locally. However, for large data sets (e.g. multi-gigabyte mailboxes), the client needs to be able to search/sort/window the data type on the server.

A query on the set of Foos in an account is made by calling Foo/query. This takes a number of arguments to determine which records to include, how they should be sorted, and which part of the result should be returned (the full list may be very long). The result is returned as a list of Foo ids.

A call to Foo/query takes the following arguments:

If an anchor argument is given, then after filtering and sorting the anchor is looked for in the results. If found, the anchor offset is then subtracted from its index. If the resulting index is now negative, it is clamped to 0. This index is now used exactly as though it were supplied as the position argument. If the anchor is not found, the call is rejected with an anchorNotFound error.

If an anchor is specified, any position argument supplied by the client MUST be ignored. If anchorOffset is null, it defaults to 0. If no anchor is supplied, any anchor offset argument MUST be ignored.

A client can use anchor instead of position to find the index of an id within a large set of results.

The response has the following arguments:

The following additional errors may be returned instead of the Foo/query response:

anchorNotFound: An anchor argument was supplied, but it cannot be found in the results of the search.

unsupportedSort: The sort is syntactically valid, but includes a property the server does not support sorting on, or a collation method it does not recognise.

unsupportedFilter: The filter is syntactically valid, but the server cannot process it.

4.5. /queryChanges

The Foo/queryChanges call allows a client to efficiently update the state of any cached foo search to match the new state on the server. It takes the following arguments:

The response has the following arguments:

The result of this is that if the client has a cached sparse array of foo ids in the results in the old state:

fooIds = [ "id1", "id2", null, null, "id3", "id4", null, null, null ]

then if it splices out all foos in the removed array:

removed = [ "id2", … ];
fooIds => [ "id1", null, null, "id3", "id4", null, null, null ]

and splices in (in order) all of the foos in the added array:

added = [{ id: "id5", index: 0, … }];
fooIds => [ "id5", "id1", null, null, "id3", "id4", null, null, null ]

and truncates or extends to the new total length, then the results will now be in the new state.

The following additional errors may be returned instead of the Foo/queryChanges response:

tooManyChanges: There are more changes the the client's maxChanges argument. Each item in the removed or added array is considered as one change. The client may retry with a higher max changes or invalidate its cache of the search results.

cannotCalculateChanges: The server cannot calculate the changes from the state string given by the client. Usually due to the client's state being too old. The client MUST invalidate its cache of the search results.

4.6. Examples

Suppose we have a type Todo with the following properties:

and the server supports querying by keyword using the syntax { hasKeyword: "foo" } in the filter argument to /query.

Now, a client might want to display the list of todos with a particular query, so it makes the following method call:

[["Todo/query", {
  "filter": { "hasKeyword": "music" },
  "sort": [{ "property": "title" }],
  "position": 0,
  "limit": 10
}, "0"],
["Todo/get", {
  "#ids": {
    "resultOf": "0",
    "name": "Todo/query",
    "path": "/ids"
}, "1"]]

This would query the server for the set of todos with a keyword of "music", sorted by title, and limited to the first 10 results. It fetches the full object for each of these Todos using backreferences to reference the result of the query. The response might look something like:

[["Todo/query", {
  "accountId": "x",
  "filter": { "hasKeyword": "music" },
  "sort": [{ "property": "title" }],
  "state": "y13213",
  "canCalculateChanges": true,
  "position": 0,
  "total": 26,
  "ids": [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" ]
}, "0"],
["Todo/get", {
  "accountId": "x",
  "state": "10324",
  "list": [{
    "id": "a",
    "title": "Practise Piano",
    "keywords": {
      "music": true,
      "beethoven": true,
      "mozart": true,
      "liszt": true,
      "rachmaninov": true
    "neuralNetworkTimeEstimation": 3600
  }, {
    "id": "b",
    "title": "Listen to Daft Punk",
    "keywords": {
      "music": true,
      "trance": true
    "neuralNetworkTimeEstimation": 18000
}, "1"]]

Now suppose the user adds a keyword "chopin" and removes the keyword "mozart" from the "Practise Piano" task. The client may send the whole object to the server, as this is a valid PatchObject:

[["Todo/set", {
  "ifInState": "10324",
  "update": {
    "a": {
      "id": "a",
      "title": "Practise Piano",
      "keywords": {
        "music": true,
        "beethoven": true,
        "chopin": true,
        "liszt": true,
        "rachmaninov": true,
      "neuralNetworkTimeEstimation": 360
}, "0"]]

or it may send a minimal patch:

[["Todo/set", {
  "ifInState": "10324",
  "update": {
    "a": {
      "keywords/chopin": true,
      "keywords/mozart": null
}, "0"]]

The effect is exactly the same on the server in either case, and presuming the server is still in state "10324" it will probably return success:

[["Todo/set", {
  "accountId": "x",
  "oldState": "10324",
  "newState": "10329",
  "updated": {
    "a": {
      "neuralNetworkTimeEstimation": 5400
}, "0"]]

The server changed the "neuralNetworkTimeEstimation" property on the object as part of this change; as this changed in a way not explicitly requested by the PatchObject sent to the server, it is returned with the "updated" confirmation.

Now, suppose another user deleted the "Listen to Daft Punk" todo. The first user will receive a push notification (see later in the spec) with the changed state string for the "Todo" type. Since the new string does not match its current state, it knows it needs to check for updates. It may make a request like:

[["Todo/changes", {
  "accountId": "x",
  "sinceState": "10324",
  "maxChanges": 50,
}, "0"],
["Todo/queryChanges", {
  "filter": { "hasKeyword": "music" },
  "sort": [{ "property": "title" }],
  "sinceState": "y13213"
  "maxChanges": 50,
}, "1"]]

and receive in response:

[["Todo/changes", {
  "accountId": "x",
  "oldState": "10324",
  "newState": "871903",
  "hasMoreChanges": false,
  "changed": null,
  "destroyed": ["b"]
}, "0"],
["Todo/queryChanges", {
  "filter": { "hasKeyword": "music" },
  "sort": [{ "property": "title" }],
  "oldState": "y13213"
  "newState": "y13218"
  "total": 25,
  "removed": ["b"],
  "added": null
}, "1"]]

5. Binary data

Binary data is referenced by a blobId in JMAP, and uploaded/downloaded separately to the core API. A blobId does not have a name inherent to it, but this is normally given in the same object that contains the blobId. The data represented by a blobId is immutable.

Any blobId that exists within an account may be used when creating/updating another object in that account. For example, an Email type may have a blobId that represents the RFC5322 representation of the message. A client could create a new Email object with an attachment and use this blobId, in effect attaching the old message to the new one. Similarly it could attach any existing existing attachment of an old message without having to download and upload it again.

When the client uses a blobId in a create/update, the server MAY assign a new blobId to refer to the same binary data from the new/updated object. If it does so, it MUST return any properties that contain a changed blobId in the created/updated response so the client gets the new ids.

A blob that is not referenced by a JMAP object (e.g. as a message attachment), MAY be deleted by the server to free up resources. Uploads (see below) are initially unreferenced blobs. To ensure interoperability:

5.1. Uploading binary data

There is a single endpoint which handles all file uploads for an account, regardless of what they are to be used for. The JMAP Session object has an uploadUrl property in [RFC6570] URI Template (level 1) format, which MAY contain a variable called accountId. The client may use this template in combination with an accountId (if required in the template) to get the URL of the file upload resource.

To upload a file, the client submits an authenticated POST request to the file upload resource.

A successful request MUST return a single JSON object with the following properties as the response:

If identical binary content to an existing blob in the account is uploaded, the existing blobId MAY be returned.

5.2. Downloading binary data

The JMAP Session object has a downloadUrl property, which is in [RFC6570] URI Template (level 1) format. The URL MUST contain a variable called blobId, MAY contain a variable called accountId, and SHOULD contain a variable called name.

The client may use this template in combination with an accountId (if required in the URL template) and blobId to download any binary data (files) referenced by other objects. Since a blob is not associated with a particular name, the template SHOULD allow a name to be substituted in as well; the server will return this as the filename if it sets a Content-Disposition header.

To download the data the client makes an authenticated GET request to the download URL with the appropriate variables substituted in. The client SHOULD send an Accept header with the content type they would like the server to return for the file. The Content-Type header of a successful response SHOULD be set to the type as requested in the Accept header by the client, or application/octet-stream if unknown and no Accept header given.

5.3. Blob/copy

Binary data may be copied between two different accounts using the Blob/copy method, rather than having to download then reupload on the client.

The Blob/copy method takes the following arguments:

The response has the following arguments:

The SetError may be any of the standard set errors that may be returned for a create.

The following additional errors may be returned instead of the Blob/copy response:

fromAccountNotFound: A fromAccountId was explicitly included with the request, but it does not correspond to a valid account.

toAccountNotFound: A toAccountId was explicitly included with the request, but it does not correspond to a valid account.

6. Push

Push notifications allow clients to efficiently update (almost) instantly to stay in sync with data changes on the server. In JMAP, push notifications occur out-of-band (i.e. not over the same connection as API exchanges), so that they can make use of efficient native push mechanisms on different platforms.

The general model for push is simple and sends minimal data over the push channel. The format allows multiple changes to be coalesced into a single push update, and the frequency of pushes to be rate limited by the server. It doesn't matter if some push events are dropped before they reach the client; it will still get all changes next time it syncs.

6.1. The StateChange object

When something changes on the server, the server pushes a StateChange object to the client. A StateChange object has the following properties:

6.2. PushSubscription

A push subscription is a message delivery context established between the client and a push service. A PushSubscription object has the following properties:

Clients may register the push subscription with the JMAP server, which will then make a POST request to the associated push endpoint whenever an event occurs.

The POST request MUST have a content type of application/json and contain the utf-8 JSON encoded StateChange object as the body. The request MUST have a TTL header, and MAY have Urgency and/or Topic headers, as specified in section 5 of [RFC8030].

If the response code is 503 (Service Unavailable), the JMAP server MAY try again later, but may also just drop the event. If the response code is 429 (Too Many Requests) the JMAP server SHOULD attempt to reduce the frequency of pushes to that URL. Any other 4xx or 5xx response code MUST be considered a permanent failure and the push subscription should be deregistered (not tried again even for future events unless explicitly re-registered by the client).

The use of this push endpoint conforms with the use of a push endpoint by an Application Server as defined in [RFC8030]. A client MAY use the rest of [RFC8030] in combination with its own Push Server to form a complete end-to-end solution, or MAY rely on alternative mechanisms to ensure the delivery of the pushed data after it leaves the JMAP server.

6.2.1. PushSubscription/set

Each session may only have a single push subscription registered. The push subscription is tied to the access token used to create it. Should the access token expire or be revoked, the push subscription MUST be removed by the JMAP server. The client MUST re-register the push subscription after reauthenticating to resume callbacks.

To set the push subscription, make a call to PushSubscription/set. It takes the following argument:

The response has no arguments.

The following additional errors may be returned instead of the PushSubscription/set response:

invalidUrl: Returned if the URL does not begin with https://, or is otherwise syntactically invalid or does not resolve.

forbidden: Returned if the URL is valid, but for policy reasons the server is not willing to connect to it.

6.2.2. PushSubscription/get

To check the currently set push subscription (if any), make a call to PushSubscription/set. It does not take any arguments. The response has a single argument:

6.3. Event Source

Clients that can hold open TCP connections can connect directly to the JMAP server to receive push notifications via a text/event-stream resource, as described in <>. This is a long running HTTP request down which the server can push data.

When a change occurs in the data on the server, it pushes an event called state to any connected clients, with the StateChange object as the data.

The server SHOULD also send a new event id that encodes the entire server state visible to the user immediately after sending a state event. When a new connection is made to the event-source endpoint, a client following the server-sent events specification will send a Last-Event-ID HTTP header with the last id it saw, which the server can use to work out whether the client has missed some changes. If so, it SHOULD send these changes immediately on connection.

The client MAY add a query parameter called closeafter with value state to the event-source resource URL when requesting the event-source resource. If set, the server MUST end the HTTP response after pushing a state event. This can be used by clients in environments where buffering proxies prevent the pushed data from arriving immediately, or indeed at all, when operating in the usual mode.

The client MAY add a query parameter called ping, with a positive integer value representing a length of time in seconds, e.g. ping=300. If set, the server MUST send an event called ping whenever this time elapses since the previous event was sent. This MUST NOT set a new event id.

The server MAY modify the interval given as a query parameter to be subject to a minimum and/or maximum value. For interoperability, servers MUST NOT have a minimum allowed value higher than 30 or a maximum allowed value less than 300.

The data for the ping event MUST be a JSON object containing an interval property, the value (type Number) being the interval in seconds the server is using to send pings (this may be different to the requested value if the server clamped it to be within a min/max value).

Clients can monitor for the ping event to help determine when the closeafter mode may be required.

Refer to the JMAP Session resource section of this spec for details on how to get the URL for the event-source resource. Requests to the resource MUST be authenticated.

A client MAY hold open multiple connections to the event-source resource, although it SHOULD try to use a single connection for efficiency.

7. Security considerations

7.1. Transport confidentiality

All HTTP requests MUST use [RFC5246] TLS (https) transport to ensure the confidentiality of data sent and received via JMAP. Clients MUST validate TLS certificate chains to protect against man-in-the-middle attacks.

7.2. Authentication scheme

A number of HTTP authentication schemes have been standardised (<>). Servers should take care to assess the security characteristics of different schemes in relation to their needs when deciding what to implement.

If offering the Basic authentication scheme, services are strongly recommended to not allow a user's regular password but require generation of a unique "app password" via some external mechanism for each client they wish to connect. This allows connections from different devices to be differentiated by the server, and access to be individually revoked.

7.3. Service autodiscovery

Unless secured by something like DNSSEC, autodiscovery of server details is vulnerable to a DNS poisoning attack leading to the client talking to an attacker's server instead of the real JMAP server. The attacker may then man-in-the-middle requests and depending on the authentication scheme, steal credentials to generate its own requests.

Clients that do not support SRV lookups are likely to try just using the /.well-known/jmap path directly against the domain of the username over HTTPS. Servers SHOULD ensure this path resolves or redirects to the correct JMAP Session resource to allow this to work. If this is not feasible, servers MUST ensure this path cannot be controlled by an attacker, as again it may be used to steal credentials.

7.4. JSON parsing

The security considerations of [RFC7159] apply to the use of JSON as the data interchange format.

7.5. Denial of service

A small request may result in a very large response, and require considerable work on the server if resource limits are not enforced. JMAP provides mechanisms for advertising and enforcing a wide variety of limits for mitigating this threat, including limits on number of objects fetched in a single method call, number of methods in a single request, number of concurrent requests, etc.

JMAP servers MUST implement sensible limits to mitigate against resource exhaustion attacks.

7.6. Push encryption

When data changes, a small object is pushed with the new state strings for the types that have changed. While the data here is minimal, a passive man-in-the-middle attacker may be able to gain useful information. To ensure confidentiality, if the push is sent via a third party outside of the control of the client and JMAP server the client MUST specify encryption keys when establishing the PushSubscription.

The privacy and security considerations of [RFC8030] and [RFC8291] also all apply to the use of the PushSubscription mechanism.

8. Normative References

[RFC2047] Moore, K., "MIME (Multipurpose Internet Mail Extensions) Part Three: Message Header Extensions for Non-ASCII Text", RFC 2047, DOI 10.17487/RFC2047, November 1996.
[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997.
[RFC2231] Freed, N. and K. Moore, "MIME Parameter Value and Encoded Word Extensions: Character Sets, Languages, and Continuations", RFC 2231, DOI 10.17487/RFC2231, November 1997.
[RFC3339] Klyne, G. and C. Newman, "Date and Time on the Internet: Timestamps", RFC 3339, DOI 10.17487/RFC3339, July 2002.
[RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 10646", STD 63, RFC 3629, DOI 10.17487/RFC3629, November 2003.
[RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data Encodings", RFC 4648, DOI 10.17487/RFC4648, October 2006.
[RFC4790] Newman, C., Duerst, M. and A. Gulbrandsen, "Internet Application Protocol Collation Registry", RFC 4790, DOI 10.17487/RFC4790, March 2007.
[RFC5051] Crispin, M., "i;unicode-casemap - Simple Unicode Collation Algorithm", RFC 5051, DOI 10.17487/RFC5051, October 2007.
[RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security (TLS) Protocol Version 1.2", RFC 5246, DOI 10.17487/RFC5246, August 2008.
[RFC5785] Nottingham, M. and E. Hammer-Lahav, "Defining Well-Known Uniform Resource Identifiers (URIs)", RFC 5785, DOI 10.17487/RFC5785, April 2010.
[RFC6186] Daboo, C., "Use of SRV Records for Locating Email Submission/Access Services", RFC 6186, DOI 10.17487/RFC6186, March 2011.
[RFC6570] Gregorio, J., Fielding, R., Hadley, M., Nottingham, M. and D. Orchard, "URI Template", RFC 6570, DOI 10.17487/RFC6570, March 2012.
[RFC6764] Daboo, C., "Locating Services for Calendaring Extensions to WebDAV (CalDAV) and vCard Extensions to WebDAV (CardDAV)", RFC 6764, DOI 10.17487/RFC6764, February 2013.
[RFC6838] Freed, N., Klensin, J. and T. Hansen, "Media Type Specifications and Registration Procedures", BCP 13, RFC 6838, DOI 10.17487/RFC6838, January 2013.
[RFC6901] Bryan, P., Zyp, K. and M. Nottingham, "JavaScript Object Notation (JSON) Pointer", RFC 6901, DOI 10.17487/RFC6901, April 2013.
[RFC7159] Bray, T., "The JavaScript Object Notation (JSON) Data Interchange Format", RFC 7159, DOI 10.17487/RFC7159, March 2014.
[RFC7230] Fielding, R. and J. Reschke, "Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing", RFC 7230, DOI 10.17487/RFC7230, June 2014.
[RFC7235] Fielding, R. and J. Reschke, "Hypertext Transfer Protocol (HTTP/1.1): Authentication", RFC 7235, DOI 10.17487/RFC7235, June 2014.
[RFC7493] Bray, T., "The I-JSON Message Format", RFC 7493, DOI 10.17487/RFC7493, March 2015.
[RFC8030] Thomson, M., Damaggio, E. and B. Raymor, "Generic Event Delivery Using HTTP Push", RFC 8030, DOI 10.17487/RFC8030, December 2016.
[RFC8291] Thomson, M., "Message Encryption for Web Push", RFC 8291, DOI 10.17487/RFC8291, November 2017.

Author's Address

Neil Jenkins FastMail Level 2, 114 William St Melbourne, VIC 3000 Australia EMail: URI: