Restore version documentation

default discord avatar
KasparTrlast year
5

I'm looking to implement the version restore function programmatically.


Having gone over the Version documentation here

https://payloadcms.com/docs/versions/overview#version-operations

I am still missing quite a lot of information on how that works, e.g which version it restores to, what exactly is the ID field, etc.



Is there more in-depth documentation on these LocalAPIs?

  • discord user avatar
    denolfe
    last year

    The endpoints follow your typical REST crud pattern. The typical process would be to list the versions first via

    GET /versions

    then perform a restore with

    POST /versions/:id

    to the specific

    id

    you want to restore. The

    id

    being the unique identifier for the version that you'd like to restore.



    What can I help clarify beyond that?

  • default discord avatar
    KasparTrlast year

    Thank you for that, this is clear. I'm thinking how versions get created, at which point exactly and are the objects in the _versions table (mongo collection) always a version behind or does _versions maintain an exact replica of what is in the main table.


    I ask this because I want to restore to a previous version (exactly one save behind) and so should I select the last version doc or one before that as the last one is a replica of the current one.

  • discord user avatar
    denolfe
    last year

    The versions endpoint will return previous versions

    and the latest

    version



    The query against the versions endpoint would look something like this:

    /api/draft-posts/versions?depth=1&where[parent][equals]=644290b95310ad615bc1ffea

    . You can also open up your Network tab while browsing around the Versions page in the Admin UI to see this.



    I don't recall if they're strictly ordered on the response, so you could also pass in something like

    sort=-createdAt

    to sort the response.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.