How to Integrate the Email Finder feature into Google Sheets

Sheets

  1. 1. If you don't have an existing Google Sheet, create a new one.

    If you don't have an existing Google Sheet, create a new one.
  2. 2. Click on Extensions

    Click on Extensions
  3. 3. Select Apps Script.

    Select Apps Script.

It will open an App Script tab.

  1. 4. Now paste the code available at the end of the page and save it (Ctrl+S or Cmd+S).

    Now paste the code available at the end of the page and save it (Ctrl+S or Cmd+S).

Go to the Icypeas website and Sign In of Sign up.

  1. 5. Select the API tab

    Select the API tab
  2. 6. There, you will find your API key, your API secret key, and your User id. Save this information.

    There, you will find your API key, your API secret key, and your User id. Save this information.
  3. 7. Go back to the App Script tab.

  4. 8. At the beginning of the code, insert your API key, API secret key, and User ID between the single quotes (''). Make sure you place each value correctly, without any extra spaces or characters as shown below.

    At the beginning of the code, insert your API key, API secret key, and User ID between the single quotes (''). Make sure you place each value correctly, without any extra spaces or characters as shown below.
  5. 9. Then click on Deploy.

    Then click on Deploy.
  6. 10. Select New deployement.

    Select New deployement.
  7. 11. Click on the gear icon.

    Click on the gear icon.
  8. 12. Select Library.

    Select Library.
  9. 13. Click on Deploy.

    Click on Deploy.
  10. 14. Click on Done.

    Click on Done.

Go back to your Google Sheet.

  1. 15. Select Extensions -> Macros -> Import macro.

    Select Extensions -> Macros -> Import macro.
  2. 16. Click on Add Function.

    Click on Add Function.
  3. 17. Click on Close.

    Click on Close.
  4. 18. Now, you can use the searchEmail() macro to find email addresses.

    Now, you can use the searchEmail() macro to find email addresses.
  5. 19. Then, you can extend the searchEmail() formula, and the result will be displayed.

    Then, you can extend the searchEmail() formula, and the result will be displayed.
  6. 20. Code to paste at step 4

    // 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 searchEmail(firstName, lastName, companyName) {
      try {
        const endpoint = `${API_BASE_URL}sync/email-search`;
        const method = 'POST';
        const payload = { firstname: firstName, lastname: lastName, domainOrCompany: companyName };
    
        const apiResponse = utils.makeApiRequest(endpoint, method, payload);
    
        for (const emailResult of apiResponse.emails) {
          const certainty = emailResult.certainty;
    
          if (certainty === 'probable' || certainty === 'sure' || certainty === 'ultra_sure') {
            return [[emailResult.email, certainty]];
          }
        }
    
        return [['not_found', '']];
      } catch (error) {
        return [['Resource not found', '']];
      }
    }