Tiny Deathstars of Foulness

Wordpress has an app. That means there’s an API to normalize communication using a predictable programmatic interface. In this case, as with many others, that’s done using a standard REST interface to communicate. The easiest way to interact with any API is to just read some stuff from the server via curl. You can feed curl the URL to the API by using your URL followed by /wp-json – as follows, assuming a URL of curl To view header information: curl -s -D - -o /dev/null In the below example we’ll ask for a list of posts by adding /wp/v2/posts to the URL: curl You’ll see a list of some posts in the output along with a little metadata about the posts. You can then grab an ID and ask for just that post, using a post ID of 48390: curl You can also see revisions that have been made to a post by appending the URL with /revisions curl You can see comments with the comments route: curl Or pages with the pages route: curl Or users with the users route: curl Or media that has been uploaded with the media route: curl And the output of each can be constrained to a single item in that route by providing the ID of the item, which shows additional metadata about the specified item. And there are routes for categories, tags, etc. There’s also some good stuff at such as which is a plugin that allows you to auth against the API. curl --user admin:krypted Not only can you look at user information, you can also add and remove posts. You would add by doing a -X followed by a POST and then feeding a file with the –data option curl --user admin:password -X POST --data @post.json The output would then include the ID of your new post to wordpress. In the following example, we’ll get rid of the post we were looking at earlier using -X and DELETE in the URL, assuming a username of admin, a password of krypted, and a post ID of 48390: curl --user admin:krypted -X DELETE If successfully deleted the response would be as follows:
{ “message”:”Deleted post” }
To dig in deeper, check out where the whole schema is documented. You can also use the GitHub site to access a command called wp (as well as PHP, node, and java clients) that can be run at the command line for simple scripting interfaces. This could allow you to, for example, simply backup posts to json files, etc. Also, it’s worth noting that various plugins will require their own interface (note there’s no themes or plugins route), such as woocommerce, interfacing with or

July 14th, 2017

Posted In: WordPress

Tags: , , , , , , , ,

The snow effect on the site was causing the pages to load slowly so it has been removed for now until I can comb through and make it less intensive. Plus, it’s not snowing any more in Minneapolis, so it isn’t really that indicative of the weather anyway. 😉

January 22nd, 2009

Posted In: sites

Tags: , ,