Created
April 24, 2015 20:50
-
-
Save HenrikJoreteg/8a6e054717c4b901dcc1 to your computer and use it in GitHub Desktop.
Gumroad Sales Data "API"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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