Pastebin Stream

This is a simple streaming (WebSocket) API, providing a live feed of (public) pastes as they are submitted to Pastebin.com. You can find the source code here.

Since Pastebin does not offer a streaming API itself, this API works by regularly polling the Pastebin API for new posts. This means that posts may be delayed by about a minute, and that they'll be broadcast in 'batches'.

Last updated

February 9, 2018: Resolved a bug that produced an unexpected error when a client sent invalid data.

Note that the application kills and restarts itself as a safety precaution when an unexpected error is encountered; if you experienced crashes while trying to use the API yesterday, those issues should now be resolved.

Preview

The latest pastes:

Usage restrictions

None. But this is a non-commercial and free service, so please be reasonable, and consider donating if this service helped you out in some way!

Can I use this from a browser?

Yes. Cross-domain connections are allowed. But again, be reasonable - if you expect to be making hundreds or thousands of simultaneous connections, please run your own proxy.

Donate

If you like this service, help keep it running by making a donation!

Donating once through PayPal

Donating monthly through PayPal

/month

Donating through Bitcoin

Please send your donation to 13quzALQ98dpJLPVcVA1rbEbE9Brf6VKyc :)

Future plans

In the future, I will likely add support for other Pastebin services as well. Suggestions are welcome - send me an e-mail!

Contact

If you need to reach me for some reason, you can e-mail me at admin@cryto.net.

API documentation

This API exposes a single endpoint, at wss://pastebin-stream.cryto.net/stream. Every command below is meant to be sent through that connection. The server expects well-formed JSON, and will kill a connection if it sends malformed data.

No special clients are required; you can simply use the standard WebSocket API in browsers. For Node.js, I recommend using the ws library. For other languages, simply use whichever WebSocket implementation is available to you.

The server sends out a 'ping' roughly every 5 seconds. If you wish to detect disconnections, this is what you'll want to check for.

Making sure you don't miss anything

The server maintains a backlog of pastes. The exact amount is subject to change, but assume "several hundred". You can make a backlog request to obtain these pastes from the backlog.

When connecting for the first time, you should do the following to obtain the maximum amount of pastes and make sure you're not left with a gap:

  1. Set up a message handler.
  2. Send a subscribe request to receive newPaste events (immediately storing pastes once they start coming in).
  3. Request a backlog after sending the subscribe request (either full or partial).
  4. Once the backlog is returned, remove any pastes that you already received through newPaste events, and then insert the backlog before the already-received pastes.

The API also includes a counter property with every paste. This is an incrementing counter managed by the server, that can be used to obtain missed pastes after a reconnect.

If you've detected a connection loss and initiated a new connection, you should do the following to obtain all the pastes you missed:

  1. Set up a message handler.
  2. Send a subscribe request to receive newPaste events (immediately storing pastes once they start coming in).
  3. Request a backlog after sending the subscribe request, specifying the since parameter - it should contain the counter of the last paste you've received on the previous connection.
  4. Once the backlog is returned, remove any pastes that you already received through newPaste events, and then insert the backlog before the already-received pastes.

Note that when the server restarts, the counter values will be reset to zero. This means that a given counter value is only unique until the next server restart.

Paste format

A paste object looks like the following:

{
	"counter": 521,
	"service": "pastebinCom",
	"id": "V2rpgLwN",
	"title": "Paste Title Goes Here",
	"date": 1489876199,
	"expiry": 0,
	"language": "text",
	"url": "http://pastebin.com/gPifdLrb"
	"contents": "[ ... paste contents go here ... ]"
}

An explanation of each of the properties:

Any optional properties may be missing. You should take this into account in your implementation.

Subscribing to pastes

{
	"type": "subscribe"
}

You should send this immediately after connecting. Once you do, you will start receiving pastes. Incoming pastes look like the following:

{
	"type": "newPaste",
	"data": <a single paste object goes here>
}

Requesting a backlog

There are a few options for request a backlog, but the response is always in the same format:

{
	"type": "backlog",
	"results": [
		... an array of paste objects goes here ...
	]
}

Requesting the full backlog

This retrieves every single paste that the server has in its backlog. Note that the response may be large.

{
	"type": "backlog",
	"all": true
}

Requesting the last X entries

This retrieves only the last X entries in the backlog, where X is an amount you specify.

{
	"type": "backlog",
	"last": 25
}

Requesting the backlog since a specific paste

This retrieves every paste in the backlog since a given counter value.

{
	"type": "backlog",
	"since": 51291
}