Authentication overview

The Yelp Fusion API uses OAuth 2.0 for authenticating requests. This industry-standard protocol allows applications to securely access Yelp's data on behalf of an authenticated client, without requiring the client to share its credentials directly with the consuming application. Developers obtain a client ID and client secret, which are then used to request an access token. This access token, typically a Bearer token, authorizes subsequent API calls for a limited duration.

OAuth 2.0 is designed to delegate authorization from a resource owner to a client. For the Yelp Fusion API, developers typically use the Client Credentials grant type, where the application itself is the "resource owner" requesting access to Yelp's public data. This method is suitable for server-to-server interactions or applications where no end-user login is involved. The Yelp Fusion API reference details the specific endpoints and parameters for token issuance and API calls.

Understanding OAuth 2.0 is crucial for secure and efficient integration. The OAuth 2.0 specification overview provides a foundational understanding of its flow and concepts, which are applied consistently by Yelp.

Supported authentication methods

Yelp primarily supports OAuth 2.0 for authentication with its Fusion API. This method ensures secure access to business data endpoints.

Yelp Fusion API Authentication Methods
Method When to Use Security Level
OAuth 2.0 (Client Credentials Grant) Server-side applications, background services, applications accessing public Yelp data without user context. High: Uses bearer tokens, token expiration, and client secret protection.

Getting your credentials

To begin authenticating with the Yelp Fusion API, you must first register your application and obtain your API credentials. Follow these steps:

  1. Create a Yelp Developer Account: Navigate to the Yelp Developer Documentation page and sign up or log in with your existing Yelp account.
  2. Create a New App: Once logged in, you will find an option to create a new application. Provide the required information for your application, such as its name and website URL.
  3. Receive Client ID and Client Secret: Upon successful application creation, Yelp will issue you a unique Client ID and Client Secret. These are your primary credentials for authenticating with the API. Keep your Client Secret confidential and do not embed it directly into front-end code or public repositories.
  4. Review API Terms: Before proceeding, familiarize yourself with the Yelp API Terms of Use, which outline usage limits, commercial restrictions, and data policies.

Once you have your Client ID and Client Secret, you can proceed to request an access token from Yelp's OAuth 2.0 token endpoint.

Authenticated request example

This example demonstrates how to obtain an OAuth 2.0 access token and then use it to make an authenticated request to the Yelp Fusion API using Python. The steps involve sending a POST request to the token endpoint with your client credentials and then including the received token in the Authorization header of your subsequent API calls.

Step 1: Obtain an Access Token


import requests

CLIENT_ID = "YOUR_CLIENT_ID"
CLIENT_SECRET = "YOUR_CLIENT_SECRET"
TOKEN_ENDPOINT = "https://api.yelp.com/oauth2/token"

# Request an access token
token_response = requests.post(
    TOKEN_ENDPOINT,
    data={
        "grant_type": "client_credentials",
        "client_id": CLIENT_ID,
        "client_secret": CLIENT_SECRET
    }
)

token_data = token_response.json()
ACCESS_TOKEN = token_data["access_token"]
TOKEN_TYPE = token_data["token_type"] # Expected: "Bearer"
EXPIRES_IN = token_data["expires_in"] # Time in seconds until expiration

print(f"Access Token: {ACCESS_TOKEN}")
print(f"Expires in: {EXPIRES_IN} seconds")

Step 2: Make an Authenticated API Request


import requests

# Assume ACCESS_TOKEN is obtained from Step 1
# ACCESS_TOKEN = "your_actual_access_token"

API_ENDPOINT = "https://api.yelp.com/v3/businesses/search"
SEARCH_PARAMS = {
    "term": "coffee",
    "location": "San Francisco"
}

headers = {
    "Authorization": f"{TOKEN_TYPE} {ACCESS_TOKEN}"
}

# Make an authenticated request to the Yelp Fusion API
api_response = requests.get(API_ENDPOINT, headers=headers, params=SEARCH_PARAMS)

if api_response.status_code == 200:
    print("Successfully authenticated and retrieved data:")
    print(api_response.json())
else:
    print(f"Error: {api_response.status_code} - {api_response.text}")

This Python example uses the requests library for HTTP communication. Ensure you replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with your actual credentials obtained from the Yelp developer portal. The Authorization header is critical, formatted as Bearer your_access_token.

Security best practices

Adhering to security best practices is essential when integrating with the Yelp Fusion API:

  • Protect your Client Secret: Your Client Secret is akin to a password. Never embed it directly into client-side code (e.g., JavaScript in a browser) or publicly accessible code repositories. Store it securely in environment variables, a secrets management service, or a configuration file that is not committed to version control.
  • Keep Access Tokens Confidential: Treat access tokens as sensitive information. While they have a limited lifespan, their exposure could allow unauthorized access to Yelp data. Transmit them over HTTPS and do not log them unnecessarily in plain text.
  • Use HTTPS for All Communications: Always ensure that all API requests, including those for obtaining access tokens and subsequent data calls, are made over HTTPS. This encrypts data in transit, protecting against eavesdropping and man-in-the-middle attacks. Yelp API endpoints are inherently protected by HTTPS.
  • Handle Token Expiration: Access tokens provided by Yelp have an expiration time. Your application should be designed to detect token expiration and automatically request a new access token when needed. The expires_in field in the token response indicates the token's validity period in seconds.
  • Implement Error Handling: Implement robust error handling for authentication failures. For instance, a 401 Unauthorized response typically indicates an invalid or expired access token. Your application should gracefully handle such errors by attempting to refresh the token or prompting for re-authentication.
  • Review Access Logs: Regularly review your application's access logs for unusual activity or repeated authentication failures, which could indicate attempted unauthorized access.
  • Minimize Permissions: While the Yelp Fusion API primarily offers public data access, it's a good practice in general to only request the minimum necessary permissions if more granular scopes were to become available in the future for other Yelp APIs.
  • Stay Updated: Keep track of any security announcements or changes to Yelp's authentication mechanisms by regularly checking the Yelp developer documentation.