Archive

History

Get document revisions and transactions

The History API lets you request document revisions by a timestamp or a revision ID. To read transactions for a document, you must have read access to the document’s current version. If your document is in a private dataset you must be authenticated.

Get a document revision

GET /v2025-02-19/data/history/:dataset/documents/:documentId

Returns a document as it was at a point in the past as JSON. This endpoint behaves exactly same as the doc endpoint. It applies current access control for every revision of the document.

Gotcha

Query Parameters

  • revision string

    Revision ID (_rev) to fetch.

  • timedatetime

    Time for which the document is fetched.

  • lastRevisionboolean

    Mutually exclusive with time and revision. Returns the current data for an existing document, or the last state before deletion for a deleted document. Added in v2025-02-19.

As these parameters refer to specific points in the history, only one of them can be specified at a time.

Example

Request with timestamp:

curl -H "Authorization: Bearer <token>" "https://exx11uqh.api.sanity.io/v2021-06-07/data/history/test/documents/b8b866a5-3546-47de-a15d-de149d058b06?time=2019-05-28T17:18:39Z"

This will return a JSON payload:

{
  "documents": [
    {
      "_createdAt": "2019-03-25T15:16:09Z",
      "_id": "b8b866a5-3546-47de-a15d-de149d058b06",
      "_rev": "mXlLqCPElh7uu0wm84cjks",
      "_type": "author",
      "_updatedAt": "2019-05-28T17:16:43Z",
      "name": "dsfasdflol"
    }
  ]
}

Gotcha

Request with revision id:

curl -H "Authorization: Bearer <token>" "https://exx11uqh.api.sanity.io/v2021-06-07/data/history/test/documents/b8b866a5-3546-47de-a15d-de149d058b06?revision=mXlLqCPElh7uu0wm84cjks"

This will return a JSON payload:

{
  "documents": [
    {
      "_createdAt": "2019-03-25T15:16:09Z",
      "_id": "b8b866a5-3546-47de-a15d-de149d058b06",
      "_rev": "mXlLqCPElh7uu0wm84cjks",
      "_type": "author",
      "_updatedAt": "2019-05-28T17:16:43Z",
      "name": "dsfasdflol"
    }
  ]
}

Get transactions for documents

GET /v2021-06-07/data/history/:dataset/transactions/:documentIds

Returns an NDJSON (Newline Delimited JSON) containing transactions for the given document ids.

URL parameter documentIds are document ids separated by comma.

Query Parameters

  • excludeContentboolean

    Exclude the document contents from the responses.

  • fromTimedatetime

    Time from which the transactions are fetched.

  • toTimedatetime

    Time until the transactions are fetched.

  • fromTransactionstring

    Transaction ID (Or, Revision ID) from which the transactions are fetched.

  • toTransactionstring

    Transaction ID (Or, Revision ID) until the transactions are fetched.

  • authorsstring

    Comma separated list of authors to filter the transactions by.

  • reverseboolean

    Return transactions in reverse order.

  • limitinteger

    Limit the number of returned transactions.

  • effectFormat"mendoza"

    "mendoza": Super efficient format for expressing differences between JSON documents. See blog

  • includeIdentifiedDocumentsOnlyboolean

    Only include the documents that are part of the document ids list

Gotcha

curl -H "Authorization: Bearer <token>" "https://exx11uqh.api.sanity.io/v2021-06-07/data/history/test/transactions/b8b866a5-3546-47de-a15d-de149d058b06?excludeContent=true"

This outputs a NDJSON payload:

{"id":"mXlLqCPElh7uu0wm84cjks","timestamp":"2019-05-28T17:16:43.151928Z","author":"pDYrmFKn7","mutations":[{"create":{"_id":"b8b866a5-3546-47de-a15d-de149d058b06","_rev":"mXlLqCPElh7uu0wm84cjks"}},{"delete":{"id":"drafts.b8b866a5-3546-47de-a15d-de149d058b06","purge":false}}],"documentIDs":["b8b866a5-3546-47de-a15d-de149d058b06","drafts.b8b866a5-3546-47de-a15d-de149d058b06"]}
{"id":"mXlLqCPElh7uu0wm84ckxR","timestamp":"2019-05-28T17:18:39.223739Z","author":"pDYrmFKn7","mutations":[{"patch":{"id":"b8b866a5-3546-47de-a15d-de149d058b06","ifRevisionID":"mXlLqCPElh7uu0wm84cjks"}},{"createOrReplace":{"_id":"b8b866a5-3546-47de-a15d-de149d058b06","_rev":"mXlLqCPElh7uu0wm84cjks"}},{"delete":{"id":"drafts.b8b866a5-3546-47de-a15d-de149d058b06","purge":false}}],"documentIDs":["b8b866a5-3546-47de-a15d-de149d058b06","drafts.b8b866a5-3546-47de-a15d-de149d058b06"]}
{"id":"3wHuOovAQT3V1vksbN2QtG","timestamp":"2019-06-11T13:06:02.028674Z","author":"psb9Tdtwv","mutations":[{"delete":{"id":"b8b866a5-3546-47de-a15d-de149d058b06","purge":false}},{"delete":{"id":"drafts.b8b866a5-3546-47de-a15d-de149d058b06","purge":false}}],"documentIDs":["b8b866a5-3546-47de-a15d-de149d058b06"]}

Was this page helpful?