Automating batch creation & update of Drafts

In developing a script to integrate my Drafts database with other tools, I want to be able to trigger potentially many updates to Drafts from an external (in this case, Python) script.

In particular, I want to:

  1. Create new drafts (with supplied content and tags)
  2. Update metadata (archive/trash/delete and apply/change tags) for existing drafts, based on their UUID.

I need to be able to reliably, and hopefully efficiently, do these for potentially many updates at once.

This raises two questions:

  1. Creating new drafts is easy with the URL scheme, but I find that repeatedly firing the URL scheme too rapidly seems to start failing. (I’m triggering the system URL handler with Python’s builtin webbrowser module, but I’m pretty sure this is a URL handler problem not a Python problem.) Is there a more reliable interface that can handle many updates without starting to fail?
  2. Are there any interfaces at all to update metadata or apply actions to existing drafts based on UUID? I thought there were, but on closer inspection I’m not seeing obvious methods in the URL scheme, and the relevant Shortcuts actions seem to assume that they’re hard-coded to point to an existing draft rather than being parameterized to take any draft (that might be loaded by UUID).

Thanks!

You would definitely be best off doing mass updates from inside Drafts with a scripted action, in terms of efficiency and reliability.

I would tend to recommend your do your external processing and generate some sort of data file that you could read in a Drafts action and process…like say a JSON file that described the series of updates you want to perform…the trigger the action to process that data.

That said, there are other approaches. URL schemes are not really great for stacking multiple calls.

Shortcuts should work fine. The updating actions take a draft object, but that can be passed as a variable from previous actions – it’s totally dynamic. If you have a UUID, us the “Get Draft by UUID” action, and pass the result of that to “Update Draft” to specify the draft, for example.

If you are just bulk creating, you could just create files in the Automatic Import inbox and let Drafts import them automatically.

1 Like