Per-Locale Publishing status not available in plugins/CMA/CDA?

Is there a way to get the current status (publish,draft,new) of a specific locale of a record inside a plugin? I cannot find any corresponding method or field in the context objects passed to the various plugin hooks.

There is also no such info in the CMA. API or Content Delivery APIā€¦

Hi @martin.palma,

Officially, we only expose this info in the UI:

Now, unofficially, under the hood that uses a secret API that you can technically access yourselfā€¦ however, that endpoint is deprecated (edit: actually, itā€™s new and still under development, i.e., ā€œalphaā€), undocumented, and subject to change at any time without warning (i.e. it may break tomorrow!). Iā€™ll check with the devs about why this is deprecated unofficial, but for now, itā€™s very much ā€œuse at your own riskā€ ā€“ please donā€™t make any long-lasting scripts with it, because it may suddenly break without warning. That said, if you want to try it anyway, here are the details (click to unblur):

The API endpoint is: https://site-api.datocms.com/items/itemId/current-vs-published-state

Or in the CMA JS client as the deprecated method client.items.currentVsPublishedState(itemId, {nested: boolean})

That will get you a response like:

{
  "id": "181065759",
  "type": "item_current_vs_published_state",
  "current_version_locales": [
    "de",
    "en",
    "es",
    "fr",
    "it",
    "pt",
    "ru",
    "sv"
  ],
  "published_version_locales": [
    "de",
    "en",
    "es",
    "fr",
    "it",
    "pt",
    "ru",
    "sv"
  ],
  "changed_locales": [
    "fr"
  ],
  "added_locales": [],
  "removed_locales": [],
  "non_localized_fields_changed": true,
  "scheduled_publication": null,
  "scheduled_unpublishing": null,
  "published_version": {
    "id": "337327958",
    "type": "item_version"
  }
}

The fields changed_locales, added_locales, and removed_locales will show you locale changes. Additionally, non_localized_fields_changed will tell you whether there are also unlocalized fields that are not yet published. If you need to do a more detailed diff, you can compare versions manually using the item-version endpoint.

Iā€™ll check with the devs to see if thereā€™s a reason this is deprecated unofficial and whether there are any replacements planned. (Edit: Not immediately, see posts below. Maybe someday!) Hope that helps in the meantime?

Hey Roger,

thanks for your feedback. Thatā€™s unfortunate that such critical information isnā€™t exposed in a official API. Hopefully this will be become a stable API endpoint.

Would be nice if you could keep us updated what the response of the Dev team isā€¦

Hey @martin.palma , the devs got back to me about this. A bit of both bad and good newsā€¦

Bad news: As for why itā€™s not official, turns out itā€™s actually just a matter of prioritization ā€“ this is a relatively new endpoint, and it just hasnā€™t been fully fleshed out yet. Dato is a relatively small company and the developers are working on many features and fixes at any given time, often with priority given to the most popular asks. Maybe this could be a feature request so they can see if others have the same need?

Now, some good news too: I was partially mistaken, and they clarified that the endpoint isnā€™t deprecated per se, just unpublicized. Maybe ā€œalphaā€ wouldā€™ve been a better term. That means even though we donā€™t consider it ready for general public use yet (no docs, not enough polish, etc.), we have no plans to get rid of it. Itā€™s still ā€œuse at your own riskā€: Weā€™re not trying to make it go away, but itā€™s not yet stable, and the request and response shapes may or may not change.

You are free to use it in the meantime, but maybe limit it to non-essential parts of the workflow, and maybe add robust error-checking to make sure the response comes back as you expect?

I know that wasnā€™t quite the response you were hoping for, and Iā€™m sorry for that, but at least I hope the transparency can help you plan around it a bit?

And if it ever gets officially prioritized and released, weā€™ll let you know!

1 Like