Skip to content

Instantly share code, notes, and snippets.

@kennymcnett
Last active February 25, 2019 05:33
Show Gist options
  • Save kennymcnett/60c2779aea79b823d663b08a7733ed9a to your computer and use it in GitHub Desktop.
Save kennymcnett/60c2779aea79b823d663b08a7733ed9a to your computer and use it in GitHub Desktop.
Domain lookup on google sheets
// Works as of April 6, 2016
// domainr docs: http://domainr.build/docs/overview
// Get your free API key from https://market.mashape.com/domainr/domainr
// Create an application, get a key
// Put your key into the cell on the "Instructions" sheet
/* sample return JSON from domainr.p.mashape.com
*
* https://domainr.p.mashape.com/v2/status?mashape-key=YOURKEYHERE&domain=testasfkljhsdf.com
*
* Produces:
*
* {"status":[{"domain":"testasfkljhsdf.com","zone":"com","status":"undelegated inactive","summary":"inactive"}]}
*
*/
function domainLookup(domain) {
if (domain == "") {
return "N/A";
}
//Get the Key from cell A11 on the sheet named "Key"
var key = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Instructions').getRange('key').getValue(); //range = named range of the cell with the API key in it
//Submit to mashape
var url = "https://domainr.p.mashape.com/v2/status?mashape-key=" + key + "&domain=";
var result = UrlFetchApp.fetch(url+domain);
var out = JSON.parse(result.getContentText());
var answer = out.status[0].summary;
//Interpret the answer
if (answer == 'undelegated' || answer == 'inactive') {
var finalAnswer = "Available";
} else {
var finalAnswer = "Nope";
}
//Logger.log(out);
//Logger.log(finalAnswer);
//Show the answer
return finalAnswer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment