Skip to content

Instantly share code, notes, and snippets.

@cnicodeme
Last active August 29, 2015 14:17
Show Gist options
  • Save cnicodeme/03cf5dfa1cbf9bd972bf to your computer and use it in GitHub Desktop.
Save cnicodeme/03cf5dfa1cbf9bd972bf to your computer and use it in GitHub Desktop.
Function to search email inside a Google Spreadsheet
/**
* Search existing emails based on the full name and the website.
*
* @param {string} token : The API token bought at https://voilanorbert.com
* @param {string} fullname : The name of the person to search
* @param {string} domain : The domain to search against.
*
* @return The list of emails or an error code (starting with "ERR-{code}")
*
* @customfunction
*/
function VN_SEARCH_EMAIL(token, fullname, domain) {
if (!token) return "Please provide a token.";
if (!fullname) return "Please provide a fullname.";
if (!domain) return "Please provide a domain.";
var request = UrlFetchApp.fetch("https://www.voilanorbert.com/api/v2/search", {
'method': 'post',
'muteHttpExceptions': true,
'payload': {
'token': token,
'name': fullname,
'domain': domain,
}
});
var objRequest = Utilities.jsonParse(request.getContentText()),
response = null;
switch(request.getResponseCode()) {
case 200:
response = objRequest.emails.join("\n");
break;
default:
if (objRequest.code) {
response = 'ERR-' + objRequest.code + ' : ' + objRequest.error;
break;
}
response = 'ERR-' + objRequest.error;
}
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment