Node library for querying the Clearbit business intelligence APIs. Currently supports:
$ npm install clearbit
var clearbit = require('clearbit')('api_key');
// or
var Client = require('clearbit').Client;
var clearbit = new Client({key: 'api_key'});
email
String: The email address to look up (required)webhook_id
String: Custom identifier for the webhook requestsubscribe
Boolean: Set totrue
to subscribe to the changesstream
Boolean: Set totrue
to use the streaming API instead of webhookstimeout
Integer: The timeout in milliseconds after which a socket closed error will be thrown.
var Person = clearbit.Person;
Person.find({email: 'email@domain.com'})
.then(function (person) {
console.log('Name: ', person.name.fullName);
})
.catch(Person.QueuedError, function (err) {
console.log(err); // Person is queued
})
.catch(Person.NotFoundError, function (err) {
console.log(err); // Person could not be found
})
.catch(function (err) {
console.log('Bad/invalid request, unauthorized, Clearbit error, or failed request');
});
domain
String: The company domain to look up (required)webhook_id
String: Custom identifier for the webhook requeststream
Boolean: Set totrue
to use the streaming API instead of webhookstimeout
Integer: The timeout in milliseconds after which a socket closed error will be thrown.
var Company = clearbit.Company;
Company.find({domain: 'www.uber.com'})
.then(function (company) {
console.log('Name: ', company.name);
})
.catch(Company.QueuedError, function (err) {
console.log(err); // Company is queued
})
.catch(Company.NotFoundError, function (err) {
console.log(err); // Company could not be found
})
.catch(function (err) {
console.log('Bad/invalid request, unauthorized, Clearbit error, or failed request');
});
name
String: The company name to look up (required)timeout
Integer: The timeout in milliseconds after which a socket closed error will be thrown.
var NameToDomain = clearbit.NameToDomain;
NameToDomain.find({name: 'Uber'})
.then(function (result) {
console.log('Domain: ', result.domain);
})
.catch(NameToDomain.NotFoundError, function (err) {
console.log(err); // Domain could not be found
})
.catch(function (err) {
console.log('Bad/invalid request, unauthorized, Clearbit error, or failed request');
});
Lookups return Bluebird promises. Any status code >=400 will trigger an error, including lookups than do not return a result. You can easily filter out unknown records from true errors using Bluebird's error class matching:
Person.find({email: 'notfound@example.com'})
.catch(Person.NotFoundError, function () {
// handle an unknown record
})
.catch(function () {
// handle other errors
});
If you really want to use node-style callbacks, use Bluebird's nodeify method:
Person.find({email: 'email@domain.com'}).nodeify(function (err, person) {
if (err) {
// handle
}
else {
// person
}
});
To get additional debug logs through needle
, the HTTP library that the client uses, set process.env.CLEARBIT_DEBUG
to true.