Instantly share code, notes, and snippets.

@OleMchls /dnsimple.gs Secret
Created Sep 14, 2018

Embed
What would you like to do?
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