WebHook URLs

There are a number of websites and services to which Draft can natively publish, including Wordpress, Reddit and Tumblr. If there's a place we don't already post, you can use this to publish data securely to wherever you have access.

Just add a URL and we'll POST your document's content to that URL.

Adding a WebHook

Go to Settings->Places to Publish and click WebHook URL.

Give your WebHook a name and the URL you'd like us to publish to.

If you'd like to test the WebHook, RequestBin is a great tool to use.

The Payload Draft will POST

Here's an example of the JSON data we'll POST to your WebHook URL.

{   
    "id": your_document_id,
    "name": "The Name of your Document",
    "content": "The plain-text markdown of your document",
    "content_html": "Your document rendered as HTML",
    "user": {
        id: 1, 
        email: 'usersemail@example.com'
    },
    "created_at": "2013-05-23T14:11:54-05:00",
    "updated_at": "2013-05-23T14:11:58-05:00"
}

This is sent as a POST with a single parameter: 'payload'. If you return a Location header when Draft calls your WebHook, we'll store the Location as a "Published" link inside Draft.

Here's an example of how you could serve up a WebHook URL with Sinatra:

require 'sinatra'
require 'json'

post '/' do
  push = JSON.parse(params[:payload])
  puts "I got some JSON: #{push.inspect}"

  headers \
    "Location"   => "http://urlofpublication.com"
end

Here's another example using Node.js and Express:

var express = require('express')
, app = express();

app.configure(function(){
    app.use(express.bodyParser());
})

app.post('/', function(req, res){
    var payload = req.body.payload;
    var parsedContent = JSON.parse(payload);
    res.set('location', "http://urlofpublication");
    res.send();
})

app.listen(3000);

Security

Note that the supplied URL should be sufficiently obscure that it can't be easily guessed. It should ideally only accept connections over https too, especially in production.

For example, use this:

https://example.com/webhooks/a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2

Rather than this:

http://example.com/webhooks/draft