Node.js client library for the Hackpad API, version 1.0.
On April 25, 2017, Hackpad announced they are shutting down.
I’m writing to let you know we’ll be shutting down Hackpad on July 19. [...] Igor Kofman, Hackpad founder and Dropbox Paper lead
They provide automated archives of pads you've created, but not all pads you have access to.
Here's how to back up all your Hackpad documents:
First, install this package: npm install -g chbrown/hackpad
Second, create a new directory and download this Makefile
into it:
IDS := $(shell cat *-ids.txt)
all: $(IDS:%=html/%.html) $(IDS:%=revisions/%.json)
personal-ids.txt:
hackpad-list > $@
html/%.html:
@mkdir -p $(@D)
hackpad-export $* > $@
revisions/%.json:
@mkdir -p $(@D)
hackpad-revisions $* > $@
Third, go to https://hackpad.com/ep/account/settings/ and copy down your Client ID and Secret like so:
export HACKPAD_CLIENT_ID=k8EXAMPLE1d
export HACKPAD_SECRET=4mEXAMPLEtj45gTlBW31mlFnEXAMPLE9
Fourth, run make personal-ids.txt
, which will list your the IDs of your personal Hackpads (the Hackpads you've created):
Fifth, create a file other-ids.txt
, and add other Hackpad IDs that you have access to and want to archive.
For example, on a "collection" page, run the following in your browser's console:
[...document.querySelectorAll('#list-of-pads-div a')].map(a =>
a.href.match(/\/(\w{11})/)).filter(m => m).map(m => m[1]).join('\n')
Copy and paste this string into the other-ids.txt
file.
Finally, run make
in the directory. This reads all the files matching *-ids.txt
in your current directory, and uses the hackpad-export
and hackpad-revisions
scripts provided by this package to download html exports into an html/
directory, and the JSON revisions into a revisions/
directory (it will create these directories as needed).
Install with npm:
npm install chbrown/hackpad
Require in your app:
const {Hackpad} = require('hackpad');
Instantiate the client with your Hackpad Oauth Client ID and secret. You can find these on the account/settings page.
const client = new Hackpad(client_id, secret);
If you have a custom Hackpad site, you can provide this via an optional argument:
const client = new Hackpad(client_id, secret, 'mycompany.hackpad.com');
Then, just run commands on your fancy new client instance:
client.create('This is an awesome hackpad');
All methods take a callback function, and JSON responses are parsed automatically:
client.create('I like this hackpad even more', (err, result) => {
if (err) throw err;
console.log('Created pad with ID=' + result.padId);
});
For non-JSON responses (like export
), the raw body is returned.
See the official API documentation for details.
client.list(callback)
client.search(query, callback)
query
is an option with the keys:q
Search term (required)start
Offset to start fromlimit
How many results to return
client.create(body, contentType, callback)
body
a string of body textcontentType
One oftext/html
,text/x-web-markdown
, ortext/plain
client.import(padId, body, contentType, callback)
padId
ID of an existing (or not-existing) padbody
a string of body textcontentType
One oftext/html
,text/x-web-markdown
, ortext/plain
client.revert(padId, revisionId, callback)
client.export(padId, revisionId, format, callback)
padId
ID of an existing padrevisionId
The revision to export; either a numeric ID or the stringlatest
format
One ofhtml
,md
,txt
, ornative
html
is recommended sincemd
andtxt
are derived from HTMLnative
just adds a lot of Ace editor markup to the HTML
client.editedSince(timestamp, callback)
padId
ID of an existing padtimestamp
A Date object
client.revisions(padId, callback)
padId
ID of an existing pad
client.revokeAccess(email, callback)
email
Email address of the user to revoke access for
client.removeUser(email, callback)
email
Email address of the user to remove
client.setEmailEnabled(email, setting, callback)
email
Email address of the user to updatesetting
true
orfalse
(as strings)
- Copyright © 2013 Lou Kosak [email protected]
- Copyright © 2017 Christopher Brown [email protected]