-
-
Save OleMchls/5cbb102f1aa3a1ab7061602a48dd9567 to your computer and use it in GitHub Desktop.
DNSimple API in Google Sheets
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
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