Posting to Blogger’s Atom API from shell using curl
Someone dropped into #atom tonight, trying to get some code working that posts to Blogger. It turns out this is very easy using nothing more than curl.
The Blogger API documentation is quite lean, and most things you do are GET
queries, for which it’s sufficient to pass -u username:password
to curl
; f.ex., you can list your weblogs using:
curl -u username:password https://www.blogger.com/atom
The only tricky part is posting and editing, which involve POST
requests with an XML body. You can do those using something like:
curl -u username:password \
-H 'Content-Type: application/xml' \
--data-binary @body.atom03 \
https://www.blogger.com/atom/weblogid
This assumes that the entry document which will be the request body lives in a file called body.atom03
. You could substitute --data-binary @-
for the respective part in the command line in case you want to pipe the data into curl
instead.
While we’re not talking about the same version of the beast here, Tim Bray is right: it’s very neat to be able to drive a web service protocol using nothing but curl
. This might catch on.