Find Website URLs
with a company name

Copied to clipboard!

    // Set-up

// 1. Replace `YOUR_API_KEY` with your Clearbit API Key. 

const clearbit_api_key = "YOUR_API_KEY"

// 2. Save the Apps Script project
//
// 3. In your sheet, simply use the function =getDomain({companyName})



/**
 * Get domain from companyName.
 *
 * @param {string} companyName.
 * @return domainName.
 * @customfunction
 */

function getDomain(companyName) {

  var url = "https://company.clearbit.com/v1/domains/find?name=" + companyName;
  var options = {
    "muteHttpExceptions": true,
    "headers": {
        "authorization": "Bearer "+clearbit_api_key
    }
  }
  var response = UrlFetchApp.fetch(url, options);
  var responseCode = response.getResponseCode();
  var responseBody = response.getContentText();
  if (responseCode === 200) {
    return JSON.parse(response).domain;

  } else {
    Logger.log(Utilities.formatString("Request failed for %s, got %d: %s", name, responseCode, responseBody));
    return false;
  }
}