Fetch the Domain and Logo

In this lesson, we'll explore two Clearbit API endpoints: the name to domain endpoint and the logo endpoint.

The name to domain API

We can use Clearbit's name to domain endpoint to fetch the domain and logo of the company. This endpoint takes the exact name of the company as a parameter and returns the best-matched domain and logo of the company in a single JSON response. Clearbit returns the data of the company with the highest website traffic. Remember that because Clearbit does a fuzzy search—a fault-tolerant search that returns approximate results rather than exact results—we might get inaccurate results sometimes.

The base URL of this endpoint is as follows:

https://company.clearbit.com/v1/domains/find?name={name_of_company}

Request parameters

This endpoint supports the following request parameters:

Name

Type

Category

Description

name

string

required

This is the name of the company we want the domain for.

Fetch the company domain and logo

Now, let's make a call to this endpoint using the code widget below. Enter the exact name of the company in place of {{NAME}} in line 13. Now, click "Run" to fetch the domain and logo of the company.

Press + to interact
import fetch from 'node-fetch';
const API_KEY = 'Bearer {{API_KEY}}';
const endpointUrl = new URL('https://company.clearbit.com/v1/domains/find');
const headerParameters = {
authorization: API_KEY,
contentType: 'application/json',
};
const queryParameters = new URLSearchParams({
name: '{{NAME}}'
});
const options = {
method: 'GET',
headers: headerParameters,
};
async function fetchData() {
try {
endpointUrl.search = queryParameters;
const response = await fetch(endpointUrl, options);
// Custom function for printing the API response
printResponse(response);
} catch (error) {
// Custom function for printing the error message
printError(error);
}
}
// Calling function to make API call
fetchData();

In the code above:

  • Line 1: We import the node-fetch library.

  • Line 5: We define the URL for the name to domain API endpoint.

  • Lines 7–10: We define the header parameters for the request, including the required API key parameter.

  • Lines 12–14: We define the query parameters for the request.

  • Lines 16–19: We set the options for the API call, specifying the HTTP request type as GET.

  • Lines 21–33: We define a function called fetchData to make the API call.

  • Lines 22–27: Within a try block, we make a call to the API, printing the response to the console.

  • Lines 28–32: We catch all errors and exceptions within a catch block and print them to the console.

  • Line 36: We invoke the fetchData function.

Response parameters

The table below explains some attributes of the output JSON response we get for this endpoint:

Name

Type

Description

domain

string

This is the website domain of the company.

logo

string

This is the URL to the logo of the company.

name

string

This is the name of the company.

The logo API

When we only want the logo and not the company's domain, we can use Clearbit's logo endpoint. It takes a required parameter—domain—and returns an image of the company's logo. We use optional parameters to adjust the logo's size, format, and saturation.

Request parameters

This endpoint supports the following request parameters:

Name

Type

Category

Description

domain

string

required

This is the website domain of the company.

size

integer

optional

This is the size of the image we request. The image size here refers to the length of the longest side in pixels, the default value is 128.

format

string

optional

This is the format of the image we request. It can either be "png" or "jpg." However, the default value is "png."

greyscale

boolean

optional

This is used to desaturate the image if passed as true. The default value is false.

Fetch the company logo

Let's fetch the logo for a particular company. Enter the domain of a company in place of DOMAIN in line 1. Now, click "Run" to execute the code.

Press + to interact
const endpointUrl = new URL('https://logo.clearbit.com/{{DOMAIN}}');
async function fetchData() {
try {
console.log("<img src="+endpointUrl+" style='display: block; margin-left:auto ;margin-right:auto;'>")
} catch (error) {
// Custom function for printing the error message
printError(error);
}
}
// Calling function to make API call
fetchData();

Response parameters

The logo endpoint simply returns the image of the company's logo in the "png" or "jpg" format if found.

Name

Type

Description

logo

png or jpg

This is the image of the company's logo.