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

- Link: https://cagrimmett.com/2023/11/09/apple-shortcuts-for-posting-to-wordpress-via-the-rest-api-and-xml-rpc-metaweblog-api/
- Published: 2023-11-09T22:18:36-05:00
- Author: Chuck Grimmett

[Jim Willis](https://www.jimwillis.org/) [asks](https://cagrimmett.com/micro/477d7b2576/),

> 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/](https://developer.wordpress.org/rest-api/reference/posts/)

Shortcut link: [https://www.icloud.com/shortcuts/182b3a80dff54b27a4d7464cfc139b81](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](https://make.wordpress.org/core/2020/11/05/application-passwords-integration-guide/#Getting-Credentials)
   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](https://developer.wordpress.org/rest-api/reference/posts/).
      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](https://codex.wordpress.org/XML-RPC_MetaWeblog_API)

Shortcut link: [https://www.icloud.com/shortcuts/4a199bb32d654721a4aac9a773c664f1](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](https://make.wordpress.org/core/2020/11/05/application-passwords-integration-guide/#Getting-Credentials)
   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](https://codex.wordpress.org/XML-RPC_MetaWeblog_API#metaWeblog.newPost).
      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

### By: Jim Willis

- Link: https://cagrimmett.com/2023/11/09/apple-shortcuts-for-posting-to-wordpress-via-the-rest-api-and-xml-rpc-metaweblog-api/#comment-33420
- Published: 2023-12-01T12:03:54-05:00

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.

Loading...
