UPDATE: See also: Posting to a Discourse forum using AppleScript.
I’ve been experimenting with accessing the Discourse API using various scripting systems. I’ll post my AppleScript code shortly, but today I’m going to show you how to do this using iOS Shortcuts.
I’ve probably made this more complex than it needs to be, but I felt like I had to break the task up into manageable pieces. The first step is to get the data needed to access the LNS forum:
- API_ADDRESS - https://forum.latenightsw.com
- API_USERNAME - your forum username
- API_KEY - the hex key string needed to access the API - you’ll need to obtain this form the forum operator
I decided to go with a JSON configuration file since Shortcuts has built-in support for JSON files. I placed a file called Discouse.json
into my iCloud Drive /Shortcuts
folder:
{
"API_ADDRESS":"https://forum.latenightsw.com",
"API_KEY":"your-api-key",
"API_USERNAME": "your-username"
}
From there, I built three Shortcuts to read the various values from this JSON file:
- Get Discourse API_ADDRESS.shortcut (1.3 KB)
- Get Discourse API_KEY.shortcut (1.3 KB)
- Get Discourse API_USERNAME.shortcut (1.2 KB)
With these Shortcuts in hand, I wrote a Shortcut to query the forum for the available topic categories and prompt the user to choose a category: “Choose Discourse Category”
- Choose Discourse Category.shortcut (3.5 KB)
And finally, I have the pieces I need to create a shortcut to post a new topic to the forum:
- Post To Discourse.shortcut (3.9 KB)
This shortcut is configured to appear in Share sheets and accepts files and text. This way, you can post to Discourse using the Share feature of most iOS apps.
I’m surprised at how powerful Shortcuts is. You have to think in a different way in order to find solutions to seemingly easy problems, but once your mind begins to work in the Shortcuts way, it flows well. I have to say that Shortcuts feels much more tractable than Automator ever did for me.
Anyway, I’ll probably post a few more Shortcuts experiments as time goes on.