Integration with Drafts via the Writeas API

I’m a longtime user of agiletortoise’s Drafts on iOS and macOS but have remained less than a novice in Javascript, which powers its configurables, “Actions.” I’ve been gradually working toward direct integration between Drafts and - you might call my workflow involving the CLI a midstep. After much fiddling, I’m pleased to report that I’ve finally accomplished this integration via the Writeas API.

Here’s a brief video demo on YouTube showing the actions in use

On the Drafts Directory:

At first run of either action, a credential identifier called “writeas” is created, which will prompt you for “Collection” and “Access Token.”

Credential Creation

“Collection” is just the backend term for blog (correct me if I’m wrong there,) so you should enter the lowercase slug of your blog. (Ex: bilge for “Access Token” is referring to a WriteFreely/Writeas/Snapas API token. (See: the docs.)

Post to Writeas will publish the current draft contents as an anonymous/“unclaimed” post. These are accessed in the “Posts” menu at /me/posts/. The URL of the result is then inserted at the cursor (in Drafts) as a markdown-formatted hyperlink.

Post to Writeas Blog will publish the current draft contents as a new post on the blog you specified at credential creation. The URL of the result is then inserted at the cursor (in Drafts) as a markdown-formatted hyperlink.


Writeas Post Example

I intend to continue exploring the possibilities of this integration and perhaps eventually publish a dedicated “Action Group.” I’d especially love to hear from any Drafts users also using Writeas/WriteFreely.

1 Like

That’s awesome, @DavidBlue! Drafts is a great writing environment, and I love the integration work that Greg at Agile Tortoise has put into the app. It really is a fantastic central point for get thoughts out of your head, and out to whatever home they need to get to.

One interesting thing is that while you can have Drafts “forget” the credentials for the service, all that does is delete the credentials from your device. In your case, since you’re using an access token, you’d normally want to send a DELETE request to the API to invalidate the token, so that it can’t be reused — but the Drafts Actions scripting reference doesn’t seem to provide a way to do that.

That means that if someone wants to delete this access token, it’s up to them to

  1. remember their access token, and
  2. make that API request manually.

It’s a bit fiddly, but if you’re already fetching that token yourself, you’re probably savvy enough to delete it yourself.

One question for you, though: both the Post to Writeas and Post to Writeas Blog actions take a collection — it seems to me that would only be necessary for the Post to Writeas Blog action. Is there a reason you’re requesting it for both?

1 Like

Only to simply things for someone intending to use both or the latter, basically, by unifying them under a single credential identifier. Maybe I should include a note in the setup step about this? It’s either that or I could set it up so the collection has to be manually identified every time in the latter, which I don’t think would be too much to do every run.

Gotcha, that makes sense!

1 Like