Salut les Growths !
Pour éviter le processus fastidieux de passer par un zapier ou de faire des téléchargements de fichiers into dropcontact into excel/gsheets j’ai demandé à une IA de me faire un appscript pour enrichir des contacts directement dans Gsheets. J’aimerais l’avis de personnes avec un profil un peu plus tech’ que moi qui n’ai jamais rééllement touché à du code,est ce que le script est bon ? Des choses à optimiser ?
Merci d’avance !
Voici le script :
function enrichPeopleDatabase() {
// Replace « API_KEY » with your Dropcontact API key
var apiKey = « API_KEY »;
// Replace the « sheetName » with the name of your sheet where the people database is stored
var sheetName = « Sheet1 »;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(sheetName);
var lastRow = sheet.getLastRow();
var range = sheet.getRange(2, 1, lastRow - 1, 3); // Assuming the email, phone number, and other information are in columns A, B, and C respectively
var values = range.getValues();
// Loop through each row and enrich the data using Dropcontact API
for (var i = 0; i < values.length; i++) {
var email = values[i][0];
var phoneNumber = values[i][1];
var otherInfo = values[i][2];
// Make API request to enrich the data
var url = "https://api.dropcontact.io/enrich";
var payload = {
"email": email,
"phone": phoneNumber,
"data": otherInfo
};
var headers = {
"Authorization": "Bearer " + apiKey,
"Content-Type": "application/json"
};
var options = {
"method": "POST",
"headers": headers,
"payload": JSON.stringify(payload)
};
var response = UrlFetchApp.fetch(url, options);
var responseData = JSON.parse(response.getContentText());
// Retrieve the enriched data
var enrichedData = responseData.data;
// Update the enriched data in the sheet
var rowRange = sheet.getRange(i + 2, 4, 1, Object.keys(enrichedData).length);
var rowValues = Object.values(enrichedData);
rowRange.setValues([rowValues]);