Skip to content

Instantly share code, notes, and snippets.

@OleMchls
Created September 14, 2018 15:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OleMchls/5cbb102f1aa3a1ab7061602a48dd9567 to your computer and use it in GitHub Desktop.
Save OleMchls/5cbb102f1aa3a1ab7061602a48dd9567 to your computer and use it in GitHub Desktop.
DNSimple API in Google Sheets
var scriptProperties = PropertiesService.getScriptProperties()
// helper functions
fetchData = function(url) {
var account_id = scriptProperties.getProperty('ACCOUNT_ID')
var token = scriptProperties.getProperty('TOKEN')
return JSON.parse(UrlFetchApp.fetch("https://api.dnsimple.com/v2/" + account_id + url, {
headers: {"Authorization": "Bearer " + token}
}).getContentText())["data"]
}
accountId = function(token) {
var response = JSON.parse(UrlFetchApp.fetch("https://api.dnsimple.com/v2/whoami", {
headers: {"Authorization": "Bearer " + token}
}).getContentText())["data"]
return "" + response.account.id // cast to string
}
// public sheet functions
function FETCHDOMAINS(token) {
scriptProperties.setProperty('TOKEN', token)
scriptProperties.setProperty('ACCOUNT_ID', accountId(token))
var response = fetchData("/domains")
var names = []
for(i = 0; i < response.length; i++) {
names.push(response[i].unicode_name)
}
return names
}
function DOMAINEXPIRES(domain) {
return fetchData("/domains/" + domain).expires_on
}
function DOMAINAUTORENEW(domain) {
return fetchData("/domains/" + domain).auto_renew
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment