yelp-api
![devDependency Status](https://david-dm.org/NickShallee/yelp-api/dev-status.svg)
This package provides a programmatic JavaScript interface for the Yelp Fusion API. The Yelp Fusion API Documentation can be viewed here.
In order to use this package, you must first get a Yelp Fusion API Key.
Installing
Simply use npm to install the package.
npm install yelp-api --save
Usage
The Yelp Fusion API has many API endpoints. Below shows how to query each of them. Reference links for each endpoint are also provided.
To query any of these endpoints, you must get your API Key from the Yelp Fusion Manage App page, located here.
Search API
This endpoint returns up to 1000 businesses based on the provided search criteria. More details here.
let yelpAPI = require('yelp-api');
let apiKey = 'YOUR_API_KEY';
let yelp = new yelpAPI(apiKey);
let params = [{ location: '20008' }];
yelp.query('businesses/search', params)
.then(data => {
console.log(data);
})
.catch(err => {
console.log(err);
});
Phone Search API
This endpoint returns a list of businesses based on the provided phone number. More details here.
let yelpAPI = require('yelp-api');
let apiKey = 'YOUR_API_KEY';
let yelp = new yelpAPI(apiKey);
let params = [{ phone: '+14159083801' }];
yelp.query('businesses/search/phone', params)
.then(data => {
console.log(data);
})
.catch(err => {
console.log(err);
});
Transaction Search API
This endpoint returns a list of businesses which support certain transactions. More details here.
let yelpAPI = require('yelp-api');
let apiKey = 'YOUR_API_KEY';
let yelp = new yelpAPI(apiKey);
let transactionType = 'delivery';
let params = [{ location: '20002' }];
yelp.query(`transactions/${transactionType}/search`, params)
.then(data => {
console.log(data);
})
.catch(err => {
console.log(err);
});
Business API
This endpoint returns the detail information of a business. More details here.
let yelpAPI = require('yelp-api');
let apiKey = 'YOUR_API_KEY';
let yelp = new yelpAPI(apiKey);
let businessId = 'four-barrel-coffee-san-francisco';
let params = [{ locale: 'en_US' }];
yelp.query(`businesses/${businessId}`, params)
.then(data => {
console.log(data);
})
.catch(err => {
console.log(err);
});
Business Match API
Thess endpoints let you match business data from other sources against our businesses based on some minimal information provided. To enable this endpoint, you must first join the Yelp Developer Beta Program. More details here.
Best Match
let yelpAPI = require('yelp-api');
let apiKey = 'YOUR_API_KEY';
let yelp = new yelpAPI(apiKey);
let params = [
{ name: 'Four Barrel Coffee' },
{ city: 'San Francisco' },
{ state: 'CA' },
{ country: 'US' }
];
yelp.query('businesses/matches/best', params)
.then(data => {
console.log(data);
})
.catch(err => {
console.log(err);
});
Lookup
let yelpAPI = require('yelp-api');
let apiKey = 'YOUR_API_KEY';
let yelp = new yelpAPI(apiKey);
let params = [
{ name: 'Four Barrel Coffee' },
{ city: 'San Francisco' },
{ state: 'CA' },
{ country: 'US' }
];
yelp.query('businesses/matches/lookup', params)
.then(data => {
console.log(data);
})
.catch(err => {
console.log(err);
});
Reviews API
This endpoint returns up to three reviews of a business ordered by Yelp's default sort order. More details here.
let yelpAPI = require('yelp-api');
let apiKey = 'YOUR_API_KEY';
let yelp = new yelpAPI(apiKey);
let params = [{ locale: 'en_US' }];
let businessId = 'four-barrel-coffee-san-francisco';
yelp.query(`businesses/${businessId}/reviews`, params)
.then(data => {
console.log(data);
})
.catch(err => {
console.log(err);
});
Autocomplete API
This endpoint returns autocomplete suggestions for search keywords, businesses and categories, based on the input text. More details here.
let yelpAPI = require('yelp-api');
let apiKey = 'YOUR_API_KEY';
let yelp = new yelpAPI(apiKey);
let params = [{ text: 'Panuccis Pizza' }];
yelp.query('autocomplete', params)
.then(data => {
console.log(data);
})
.catch(err => {
console.log(err);
});
Event Lookup API
This endpoint returns the detailed information of a Yelp event. To enable this endpoint, you must first join the Yelp Developer Beta Program. More details here.
let yelpAPI = require('yelp-api');
let apiKey = 'YOUR_API_KEY';
let yelp = new yelpAPI(apiKey);
let params = [{ locale: 'en_US' }];
let eventId = 'oakland-saucy-oakland-restaurant-pop-up';
yelp.query(`events/${eventId}`, params)
.then(data => {
console.log(data);
})
.catch(err => {
console.log(err);
});
Event Search API
This endpoint returns events based on the provided search criteria. To enable this endpoint, you must first join the Yelp Developer Beta Program. More details here.
let yelpAPI = require('yelp-api');
let apiKey = 'YOUR_API_KEY';
let yelp = new yelpAPI(apiKey);
let params = [{ locale: 'en_US' }];
yelp.query('events', params)
.then(data => {
console.log(data);
})
.catch(err => {
console.log(err);
});
Featured Event API
This endpoint returns the featured event for a given location. To enable this endpoint, you must first join the Yelp Developer Beta Program. More details here.
let yelpAPI = require('yelp-api');
let apiKey = 'YOUR_API_KEY';
let yelp = new yelpAPI(apiKey);
let params = [{ location: '20002' }];
yelp.query('events/featured', params)
.then(data => {
console.log(data);
})
.catch(err => {
console.log(err);
});
Contributing
I would very much appreciate your contributions to this project Make any pull requests on the GitHub repo.
Authors
See also the list of contributors who participated in this project.
License (MIT)
Copyright 2018 Nick Shallee
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.