
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThe History API's /data/history/:dataset/transactions/:id endpoint does give you access to transaction data with the actual content changes, which allows you to do field-level diffs. The key is understanding which parameters to use and how to interpret the response.
When you call the transactions endpoint, the response is in NDJSON format and includes mutations for each transaction. These mutations show the actual changes made to documents.
excludeContent (boolean, default: false, required)
false (the default) to get the actual document content and changestrue would only give you transaction metadata without the changes themselveseffectFormat (string, default: "mendoza")
// Fetch transactions with full content
const response = await fetch(
`https://${projectId}.api.sanity.io/v2023-02-01/data/history/${dataset}/transactions/${documentId}?excludeContent=false&effectFormat=mendoza`,
{
headers: {
Authorization: `Bearer ${token}`
}
}
)
// Response is NDJSON - each line is a transaction
const ndjson = await response.text()
const transactions = ndjson.trim().split('\n').map(line => JSON.parse(line))
// Each transaction contains mutations showing what changed
transactions.forEach(transaction => {
console.log('Transaction ID:', transaction.id)
console.log('Timestamp:', transaction.timestamp)
console.log('Mutations:', transaction.mutations)
// Mutations contain the actual changes
transaction.mutations.forEach(mutation => {
if (mutation.patch) {
// Patch operations show field-level changes
console.log('Patched fields:', mutation.patch)
}
if (mutation.create || mutation.createOrReplace) {
// Full document on create
console.log('Created document:', mutation.create || mutation.createOrReplace)
}
})
})The mutations array in each transaction contains operations that show exactly what changed:
patch operations show field-level modifications with set, unset, inc, etc.create / createOrReplace operations include the full documentdelete operations show document removalFor patch operations specifically, you'll see the exact fields being modified, which gives you the field-level diff you're looking for.
The endpoint also supports:
fromTime / toTime - Filter by timestamp rangefromTransaction / toTransaction - Filter by transaction ID rangereverse - Get transactions in reverse chronological orderlimit - Limit number of transactions returnedThese parameters help you narrow down to specific time periods or transaction ranges when building your diff functionality.
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store