Skip to content

Instantly share code, notes, and snippets.

@HenrikJoreteg
Created April 24, 2015 20:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HenrikJoreteg/8a6e054717c4b901dcc1 to your computer and use it in GitHub Desktop.
Save HenrikJoreteg/8a6e054717c4b901dcc1 to your computer and use it in GitHub Desktop.
Gumroad Sales Data "API"
// There's no way to retrieve detailed sales info from Gumroad.com through
// their official API.
// This bypasses that by posting a login form and then hitting an API only accessible
// via AJAX with a session cookie
// you just need USERNAME and PASSWORD set as environment variables where this is ran
var request = require('request');
module.exports = function (cb) {
var jar = request.jar();
request.get({
url: "https://gumroad.com/analytics",
jar: jar
}, function (err, req, body) {
var tokenTest = /\"authenticity_token\" type=\"hidden\" value=\"(\S+)\"/;
var loginForm = {
utf8: "✓",
next: "",
authenticity_token: tokenTest.exec(body)[1],
"user[login]": process.env.USERNAME,
"user[password]": process.env.PASSWORD
};
request.post({
url: "https://gumroad.com/login",
form: loginForm,
jar: jar
}, function (err, req, body) {
var today = new Date();
request.get({
url: "https://gumroad.com/analytics/data/by_date",
qs: {
// date started selling
start_time: (new Date(2013, 9, 6)).toString(),
end_time: today.toString()
},
json: true,
jar: jar
}, function (err, req, body) {
cb(err, body)
});
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment