clearbit / clearbit-node

Node library for querying the Clearbit business intelligence APIs
https://clearbit.com/docs
MIT License
69 stars 35 forks source link

Just doesn't work #27

Closed dylandechant closed 7 years ago

dylandechant commented 7 years ago

this code (node 7.10.1):

const Client   = require('clearbit').Client;
const clearbit = new Client({key: process.env.clearbitKey});

let Organization = clearbit.Company;
Organization.find({domain: req.body.url).then((company) => {
    console.log('Name: ', company.name);
  }).catch(Company.QueuedError, (err) => {
    console.log(err); // Company is queued
  }).catch(Company.NotFoundError, (err) => {
    console.log(err); // Company could not be found
  }).catch((err) => {
    console.log('Bad/invalid request, unauthorized, Clearbit error, or failed request');
    console.log('err');
  });

throws this error:

➜  git:(feature/clearbit) ✗ node clearbit.js
app.js:10
Organization.find({domain: req.body.url).then((company) => {
                                       ^
SyntaxError: Unexpected token )
    at createScript (vm.js:53:10)
    at Object.runInThisContext (vm.js:95:10)
    at Module._compile (module.js:543:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:427:7)
    at startup (bootstrap_node.js:151:9)

either the docs are outdated or the package is broken

dylandechant commented 7 years ago

HEH. whoops.

maccman commented 7 years ago

Looks like you're missing a bracket?

dylandechant commented 7 years ago

yessir! i did find something wrong in your docs though in the api reference in my account:

var clearbit = require('clearbit')('=');

clearbit.Company.find({domain: 'uber.com'})
  .then(function (company) {
    console.log('Name: ', company.name);
  })
  .catch(Company.QueuedError, function (err) {
    // Company lookup queued - try again later
  })
  .catch(Company.NotFoundError, function (err) {
    // Company could not be found
    console.log(err);
  })
  .catch(function (err) {
    console.error(err);
  });

should be:

var clearbit = require('clearbit')('=');

clearbit.Company.find({domain: 'uber.com'})
  .then(function (company) {
    console.log('Name: ', company.name);
  })
  .catch(clearbit.Company.QueuedError, function (err) {
    // Company lookup queued - try again later
  })
  .catch(clearbit.Company.NotFoundError, function (err) {
    // Company could not be found
    console.log(err);
  })
  .catch(function (err) {
    console.error(err);
  });

notice the difference in the catch statements?

maccman commented 7 years ago

We might need to roll your key 😬. Want to contact support@clearbit.com

dylandechant commented 7 years ago

haha, yes, realized that a minute after i posted. Thanks!