// 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,
}
};
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 scrapeProfile(url) {
try {
const endpoint = `${API_BASE_URL}scrape/profile?url=${url}`;
const method = 'GET';
const apiResponse = utils.makeApiRequest(endpoint, method);
if (apiResponse["success"] === true) {
let result = '';
for (const key in apiResponse["result"]) {
const value = apiResponse["result"][key];
if (Array.isArray(value)) {
result += `${key}:\n`;
value.forEach((item, index) => {
if (typeof item === 'object' && item !== null) {
for (const subKey in item) {
result += ` ${subKey}: ${item[subKey]}\n`;
}
} else {
result += ` - ${item}\n`;
}
});
} else {
result += `${key}: ${value}\n`;
}
}
return result;
} else {
return [['Resource not found', '']];
}
} catch (error) {
return [['Resource not found', '']];
}
}