Publishing to a WordPress Blog via XML-RPC (Part 2)
Please refer to this post for some background.
Using XML-RPC, you can create new blog posts, delete posts, edit posts, add categories, delete categories, etc.
XML-RPC operates over HTTP (the protocol we use to access a typical Web page). You send information in a request to the server, and the server replies with a response, telling you whether it was successful, etc. Both the request and the response must be text in a specific format (using XML structure). The format you use depends on what you’re trying to accomplish. For example, let’s say you want to post something new to your blog via XML-RPC; you would send this request:
<?xml version="1.0"?> <methodCall> <methodName>metaWeblog.newPost</methodName> <params> <param><value>1</value></param> <param><value>userName</value></param> <param><value>password</value></param> <param><value> <struct> <member><name>description</name><value>This is the body of the message</value></member> <member><name>title</name><value>This is the new title</value></member> </struct> </value></param> <param><value>1</value></param> </params> </methodCall>
If it were successful, the response would be something like the following:
<?xml version="1.0"?> <methodResponse> <params> <param> <value> <string>111</string> </value> </param> </params> </methodResponse>
The 111 would be the post ID for the new post.
One of the challenges of using XML-RPC is to find the specific XML format for each of the tasks you want to perform. It is not documented all in one place that I could find. This site is more helpful than others, but you should be aware that it doesn’t match up exactly with what WordPress supports. You can find out what WordPress supports by invoking mt.supportedMethods, which will be explained later.