Avoiding lost changes when using the REST API with Collaborative Editing turned on

We have release automation that updates Confluence pages using the REST API, and we have Collaborative Editing turned on in our environment. We periodically run into the problem documented here – Editing shared draft shows an old version of the page | Confluence | Atlassian Documentation.

Does anyone know what sequence of API calls would be equivalent to the “Revert to Last Published Version” option? I’m thinking if we could do that every time the automation updates the page, that would fix it.

As a less desirable but still perhaps viable option, does anybody know how to either (or both) 1) reliably detect the existence of a shared draft or 2) created a shared draft? I’m getting the impression that the behavior of the API depends on whether a shared draft already exists (created by a human user) or not.

Pointers, or ideally examples, would be greatly appreciated. Thanks.