Apple Shortcuts for posting to WordPress via the REST API and XML-RPC MetaWeblog API

Jim Willis asks,

it seems that the iOS WordPress app’s “Post to WordPress” is no longer working, so I’d like to fallback to the rpc endpoint. Any chance you could share a link to your shortcut so I could take a look what you did here?

Certainly! I’m replying as a post because I think it might help other people, too.

I made two versions, one using the REST API and one using the XML-RPC MetaWeblog API.

REST API

Docs for making posts with the WordPress REST API: https://developer.wordpress.org/rest-api/reference/posts/

Shortcut link: https://www.icloud.com/shortcuts/182b3a80dff54b27a4d7464cfc139b81

How it works:

  • Takes input for a title and content. These are turned into variables.
    • If you don’t want a title, you can change this, but make sure your theme supports not having titles.
  • When you first set up the shortcut, add your username and an Application password in the format: username:password in the provided text block. This gets base64 encoded and passed to the cURL request as a basic authorization header.
  • The Get Content of URL block makes a POST to /wp-json/wp/v2/posts (Update your domain here!)
    • The variables for title and content get passed into the appropriate key in the JSON request body. I included title, content, and status, as those are the three that are needed. You can include tags, categories, slug, excerpt, etc. Anything in the docs. All pretty simple, you just need to make more variables and pass them along in the JSON body.
  • I included a block that gets the link back from the successful POST and prompts you to view it. Feel free to remove it if you don’t like it.

XML-RPC MetaWeblog API

Docs for the WordPress XML-RPC MetaWeblog API: https://codex.wordpress.org/XML-RPC_MetaWeblog_API

Shortcut link: https://www.icloud.com/shortcuts/4a199bb32d654721a4aac9a773c664f1

How it works:

  • Takes input for a title and content. These are turned into variables.
    • If you don’t want a title, you can change this, but make sure your theme supports not having titles.
  • When you first set up the shortcut, add your username and an Application password in the provided text blocks. These get turned into variables and passed to the XML that we send to xmlrpc.php.
  • The XML is stored as a text block, which is then turned into a variable and passed as a file along with the request.
    • I only included the username, password, post title, and post content, but you can add whatever is supported by the API. You just need more variables and more members of the struct.
  • The Get Contents of URL block makes a POST to the /xmlrpc.php endpoint (change the value for your domain!) with Content-Type of text/xml and the request body as a file.

If you run into any issues, let me know! I’m happy to help.



Comments

One response to “Apple Shortcuts for posting to WordPress via the REST API and XML-RPC MetaWeblog API”

  1. Hey, first off, thank you!
    Secondly, if you were picking the more secure route here, would you got for the base64 user/pwd or the xml-rpm Application Password? Just curious. I just got done writing a python script to do some automation work on my WP and used the Application Password route but wonder if I should have done the base64 method. Would be really curious to hear your thoughts. And thanks again for these great shortcuts.

Leave a Reply

Webmentions

If you've written a response on your own site, you can enter that post's URL to reply with a Webmention.

The only requirement for your mention to be recognized is a link to this post in your post's content. You can update or delete your post and then re-submit the URL in the form to update or remove your response from this page.

Learn more about Webmentions.