Skip to content

Instantly share code, notes, and snippets.

Created June 7, 2021 20:42
Show Gist options
  • Save GoodBoyNinja/fe231f0e5e9bcd9241d06cfbbd8a6e6b to your computer and use it in GitHub Desktop.
Save GoodBoyNinja/fe231f0e5e9bcd9241d06cfbbd8a6e6b to your computer and use it in GitHub Desktop.
If you are planning on uploading a script to Gumroad you can use this function in order to contact Gumroad through the script, and receive a response. Note that it uses JSON.parse, which means you need to have json2.js included in your code in order to convert the response into an object. You can learn more about it here:…
function GumrdLicenseRequest(licenseKeyInput, incrementUseCount, showDialogs) {
// better check here if there is access to files and network
var showDialogs = (showDialogs == undefined) ? true : showDialogs;
licenseKeyInput == undefined ? undefined : licenseKeyInput;
incrementUseCount == undefined ? false : String(incrementUseCount);
if (
permalink == undefined ||
licenseKeyInput == undefined ||
incrementUseCount == undefined
) {
// information is missing, you could print or alert an error
return false;
// make first contact
var gumroadResponse = "";
try {
gumroadResponse =
'curl -d "product_permalink=' +
permalink +
'" -d "license_key=' +
licenseKeyInput +
'" -d "increment_uses_count="' +
incrementUseCount +
" -X POST"
) || "";
} catch (e) {
gumroadResponse = "";
// something went wrong, you could print or alert the error
// finalize the gumroad response as a string
gumroadResponse =
) || "";
// if can establish connection with gumroad, convert the response into an object
var gumroadRespnseObject = null;
try {
gumroadRespnseObject = JSON.parse(gumroadResponse) || "";
} catch (e) {
// something went wrong parsing the response, you can print or alert the error
gumroadRespnseObject = null;
if (gumroadRespnseObject && gumroadRespnseObject.success !== undefined) {
// gumroad reached succesfully, return the response as an object
return gumroadRespnseObject;
} else {
// did not seem to reach gumroad, probably because no connection to the network has been established
if (showDialogs) {
alert("Can't reach Gumroad. Are you connected to the internet?");
return false
// if made it here contacting gumroad failed for another reson.
if (showDialogs) {
alert("Could not contact Gumroad");
return false;
Copy link

Thanks for this!
Just a heads up that "permalink" isn't defined or passed into this function so the function currently returns false unless "permalink" is added :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment