😎 Discover cool tips and tricks for customization in our next Developer Deep Dive virtual event - sign up now!

Using History API to get changed fields and author's name in Sanity.io

6 replies
Last updated: Feb 28, 2023
Using the History API, is there a way to get the exact fields that have been changed, so I can do a diff on them?I've used the
/v2023-02-01/data/history/:dataset/transactions/:id
endpoint to get all the transactions, but I need to get access to the content to do a diff.
Feb 24, 2023, 5:32 PM
Also any way to extract the author's actual name instead of the id?
Feb 24, 2023, 5:46 PM
You would want to do something like this for every item on your list.

curl -H "Authorization: Bearer <token>" "<https://exx11uqh.api.sanity.io/v2021-06-07/data/history/test/documents/b8b866a5-3546-47de-a15d-de149d058b06?revision=mXlLqCPElh7uu0wm84cjks>"
The important thing to pass here is the
_rev
id.
Feb 25, 2023, 1:02 PM
Thanks! That's exactly it. Not sure how I missed that in the docs. Any idea about extracting the author's actual name
Feb 26, 2023, 6:50 PM
I think I would make a fetch request with GROQ
[_type == "<your document type>" && _rev == "<rev id>"] { …, author-> }
That is basically getting the references of the author (just assuming)
Feb 27, 2023, 1:22 PM
Thanks, I found the endpoint I needed.

users/:userId
Feb 27, 2023, 5:36 PM
awesome. way to go
user F
😊
Feb 28, 2023, 1:12 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?