Last active
August 29, 2015 14:00
-
-
Save mhawksey/11234995 to your computer and use it in GitHub Desktop.
Google Apps Script equivalent to import.io PHP example - see http://mashe.hawksey.info/2014/04/using-google-apps-script-integrate-import-io/
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 userGuid = "5895d593-9461-4b8b-8452-95bb82458bd2"; | |
var apiKey = "YOUR_API_KEY"; | |
/** | |
* Query importio for data. | |
* | |
* @param {string} connectorGuid the number we're raising to a power | |
* @param {object} input the exponent we're raising the base to | |
* @param {string} userGuid the exponent we're raising the base to | |
* @param {string} apiKey the exponent we're raising the base to | |
* @param {string} additionalInput the exponent we're raising the base to | |
* @return {object} the result of the exponential calculation | |
*/ | |
function query(connectorGuid, input, userGuid, apiKey, additionalInput) { | |
var url = "https://api.import.io/store/connector/" + connectorGuid + "/_query?_user=" + encodeURIComponent(userGuid) + "&_apikey=" + encodeURIComponent(apiKey); | |
var data = {"input": input}; | |
if (additionalInput) { | |
data["additionalInput"] = additionalInput; | |
} | |
var options = { "method": "POST", | |
"payload": JSON.stringify(data)}; | |
try { | |
var response = UrlFetchApp.fetch(url, options); | |
return JSON.parse(response.getContentText()); | |
} catch(e) { | |
return e; | |
} | |
} | |
function getImportioExample(){ | |
// Query for tile Integrate Page Example | |
var result = query("caff10dc-3bf8-402e-b1b8-c799a77c3e8c", {"searchterm": "avengers 2",}, userGuid, apiKey, false); | |
Logger.log(result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment