// Replace "API-KEY" with your API Key
const API_KEY = '';
// Replace "API-SECRET" with your API Secret
const API_SECRET = '';
// Replace "USER-ID" with your user ID
const USER_ID = '';
const API_BASE_URL = 'https://app.icypeas.com/api/';
const utils = {
sha1:function (str){
const buffer = Utilities.newBlob(str).getBytes();
const hash = Utilities.base64Encode(Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_1, buffer));
return hash;
},
generateSignature: function(endpoint, method, secret, timestamp) {
if (!endpoint) {
throw new Error('Endpoint cannot be empty');
}
const payload = `${method}${endpoint}${timestamp}`.toLowerCase();
const signature = utils.sha1(payload);
return { signature, timestamp };
},
makeApiRequest:function(endpoint, method, payload = {}) {
const timestamp = new Date().toISOString();
const { signature, timestamp: authTimestamp } = utils.generateSignature(endpoint, method, API_SECRET, timestamp);
const params = {
method,
headers: {
'Content-Type': 'application/json',
'Authorization': `${API_KEY}:${signature}`,
'X-ROCK-TIMESTAMP': authTimestamp,
},
payload: JSON.stringify(payload),
};
try {
const response = UrlFetchApp.fetch(endpoint, params);
const jsonResponse = response.getContentText();
return JSON.parse(jsonResponse);
} catch (error) {
console.log('API Request Failed. Error:', error);
console.log('Full Server Response:', error.getContentText());
throw error;
}
},
}
function verifyEmail(email) {
try {
const endpoint = `${API_BASE_URL}sync/email-verification`;
const method = 'POST';
const payload = { email: email };
const apiResponse = utils.makeApiRequest(endpoint, method, payload);
if (apiResponse.status == "NOT_FOUND"){
return "not_found";
} else {
return apiResponse.emails[0].certainty;
}
} catch (error) {
return [['Resource not found', '']];
}
}