Authorization Code Workflow
Authorization Code Workflow
Make sure you've read through the overview and the prerequisites
Workflow
- Create a PKCE code verifier and code challenge.
- Redirect the user to Yelp's authorization page.
- After the user authorizes your application, Yelp redirects their browser back to your application with an authorization code.
- Redeem the authorization code for an access token.
- Use the access token to make requests on behalf of the user.
The workflow is the same for business users and consumers. Only the authorization page and the scopes are different. See Which Authorization Page to Use.
Step 1: Create a PKCE Code Verifier and Challenge
PKCE ties the authorization code to your application, so a stolen code is no use to anyone else. Yelp supports the S256 method only.
- Generate a random
code_verifierof 43 to 128 characters, using onlyA-Z,a-z,0-9,-,.,_and~. - Set
code_challengeto the base64url-encoded SHA-256 hash of thecode_verifier, without padding. - Keep the
code_verifieruntil Step 3. Don't send it in the authorization request.
import base64
import hashlib
import secrets
code_verifier = secrets.token_urlsafe(64)
code_challenge = (
base64.urlsafe_b64encode(hashlib.sha256(code_verifier.encode("ascii")).digest())
.rstrip(b"=")
.decode("ascii")
)
Step 2: Redirect the User to Yelp's Authorization Page
Your application must redirect the user's browser to Yelp's authorization URL. This is a GET request, and you must provide the parameters below. The user signs in if needed, reviews your application's name and the permissions (scopes) you requested, and chooses to continue or cancel.
Note
The authorization page contains an
X-Frame-Options SAMEORIGINheader. This prevents the page from being embedded in a non-Yelp frame.
Which Authorization Page to Use
Use the page that matches the user's account type. A request can't mix business and consumer scopes, and a scope for the other account type is never granted.
| User | Authorization URL | Scopes |
|---|---|---|
| Business user | https://biz.yelp.com/oauth2/authorize | Business scopes, such as leads |
| Consumer | https://www.yelp.com/oauth2/authorize | Consumer scopes: projects and project_actions |
GET https://biz.yelp.com/oauth2/authorize
Parameters
| Parameter | Required | Description |
|---|---|---|
client_id | Required | ID assigned by Yelp for the third-party system that will make user-authorized requests to Yelp. |
redirect_uri | Required | Where Yelp sends the user after they authorize your application, with the authorization code. It must use https and exactly match a redirect URI registered for your application. Yelp doesn't ignore a trailing slash, match a prefix, or fall back to a default.Contact your Yelp relationship manager to register a redirect URI. |
response_type | Required | A string denoting the type of response. In the case of requesting an authorization code, this value will be code. |
scope | Required | A space delimited list of actions that the user is authorizing your application to perform. Business scopes (use with biz.yelp.com):leads - enables reading leads and responding to them.r2r - enables respond to review permission.r2r_get_businesses - enables the ability to retrieve a list of businesses that the business owner has "claimed" aka businesses that this user can respond to reviews for.r2r_business_owner - enables the ability to retrieve information about the business owner like username and profile photo.Consumer scopes (use with www.yelp.com):projects - enables working with the consumer's projects.project_actions - enables taking actions on the consumer's projects.Yelp must enable your application for each scope, do not request scopes you don't have access to. Don't mix business and consumer scopes in one request. |
state | Recommended | A unique string generated by your application for each request, to maintain state between the request and the callback. Yelp returns it unchanged on the redirect. Used to prevent CSRF |
code_challenge | Required | The PKCE code challenge from Step 1. |
code_challenge_method | Required | Must be S256. |
Request Template
https://biz.yelp.com/oauth2/authorize?client_id=itk2LQ1r9e88jEjKiGae1w&redirect_uri=https%3A%2F%2Fwww.example.com%2Fredirect_endpoint&response_type=code&scope=leads&state=some_unique_string&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256
https://www.yelp.com/oauth2/authorize?client_id=itk2LQ1r9e88jEjKiGae1w&redirect_uri=https%3A%2F%2Fwww.example.com%2Fredirect_endpoint&response_type=code&scope=projects%20project_actions&state=some_unique_string&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256
The user will be shown a confirmation dialog naming your application and the permissions (scopes) you requested:

Example business user dialog on yelp.com
Response
Once the user has signed in and authorized your application, Yelp redirects the browser to your redirect_uri with these query parameters:
| Parameter Name | Description |
|---|---|
| code | A unique code that your application uses to redeem an access token. |
| state | The state you sent in the authorization request. Verify this is the same as in the request to Yelp to prevent CSRF |
| iss | The issuer of the response: https://api.yelp.com/oauth2/biz if the user authorized on biz.yelp.com, or https://api.yelp.com/oauth2/consumer if they authorized on www.yelp.com. |
Check iss before you use the code. It must be the issuer for the authorization page you used, as listed above. If it isn't, discard the response. This protects your application from a response that was meant for a different authorization server. See RFC 9207.
https://www.example.com/redirect_endpoint?code=54321&state=some_unique_string&iss=https%3A%2F%2Fapi.yelp.com%2Foauth2%2Fbiz
If the user chooses Cancel, they are sent to yelp.com and your application isn't notified. Your application doesn't receive a redirect.
Step 3: Redeem the Authorization Code for an Access Token
The authorization code expires in 5 minutes and can be used once, so redeem it immediately. Verify that state and iss match what you expect before you do.
Send the code to Get Access Token v4 (POST https://api.yelp.com/oauth2/token/v4), along with the code_verifier from Step 1 and the same redirect_uri you sent in Step 2. Send client_id and client_secret in the form body.
POST /oauth2/token/v4 HTTP/1.1
Host: api.yelp.com
Content-Type: application/x-www-form-urlencoded
client_id={client_id}&
client_secret={client_secret}&
grant_type=authorization_code&
code={code}&
redirect_uri={redirect_uri}&
code_verifier={code_verifier}
The response includes an access token that expires in 1 hour and a refresh token that expires in 90 days by default:
{
"access_token": "<128_character_long_string>",
"token_type": "Bearer",
"expires_in": 3600,
"expires_on": "2026-11-10T20:00:00+00:00",
"refresh_token": "<128_character_long_string>",
"refresh_token_expires_in": 7776000,
"refresh_token_expires_on": "2027-02-08T19:00:00+00:00",
"scope": "leads"
}
Check scope in the response. It lists the scopes the user actually granted, which can be fewer than you requested:
- On
biz.yelp.com, a scope that isn't enabled for your application is left out instead of causing an error. The authorization page only lists the scopes that remain. If none remain, it says your application isn't requesting any information, and the response has noscopefield. A token with no scopes can't call any Yelp API, so check which scopes are enabled for your application. - On
www.yelp.com, a scope that is unknown or isn't enabled for your application stops the request with an error page instead (see Errors on the Authorization Page).
When the access token expires, use the refresh token to get a new one (see Step 5).
Endpoint documentation:
TOKEN_V4_REQUIRED
If Get Access Token v2 or v3 returns
400with the error codeTOKEN_V4_REQUIRED, your application must use v4. See Get Access Token v2 and v3.
Step 4: Use the Access Token to Make Requests on Behalf of the User
Once you have the access token you can start making API calls to all oauth secured Yelp APIs which are included in the scopes you have requested. You must include the access token in the Authorization header of the HTTP call.
Request Template
curl -X GET https://partner-api.yelp.com/token/v1/businesses -H 'Authorization: Bearer <access_token>'
Example: Retrieve businesses associated with access token
You can retrieve a list of all open businesses associated with a specific business user's access token.
Endpoint documentation:
Consumer Access Tokens
A consumer's access token works with the consumer endpoints in the Home Services API, such as listing the consumer's projects and sending messages in their conversations. Each endpoint acts only on the consumer who authorized your application.
A business user's access token only works on business endpoints, and a consumer's access token only works on consumer endpoints. If you serve both, keep their tokens apart and call each endpoint with the right one. See Errors When Calling an Endpoint.
Step 5: Refresh the Access Token
Every refresh on v4 returns a new refresh token, and the one you sent stops working. Store the new refresh token every time. For the request, the retry window and the errors, see the Refresh Tokens guide:
Revoke Access Token
The authorization server responds with HTTP status code 200 if the token has been revoked successfully or if the client submitted an invalid token.
Endpoint documentation:
Token Lifetimes
| v4 | v2 and v3 | |
|---|---|---|
| Authorization code | 5 minutes | 5 minutes |
| Access token | 1 hour | 7 days |
| Refresh token | 90 days by default | 365 days by default |
Use the expiry fields in each token response (expires_on and refresh_token_expires_on) rather than hard-coding the lifetimes. If you have an agreement with Yelp for longer-lived refresh tokens, contact your Yelp relationship manager before you move to v4.
Error Scenarios
Errors on the Authorization Page
Yelp doesn't redirect to your redirect_uri when an authorization request is invalid, and it doesn't send an error parameter. The user sees an error page that says "Woops! Something doesn't look right. Please contact the client where this request came from." The page doesn't say what was wrong, and your application isn't notified.
If a user reports this page, check the following:
code_challengeis missing, orcode_challenge_methodisn'tS256.redirect_uriis missing, doesn't usehttps, or isn't an exact match for a registered redirect URI.response_typeisn'tcode.- On
www.yelp.com:scopeis missing, or has a value that is unknown, isn't enabled for your application, or is a business scope, or it mixes business and consumer scopes. - On
biz.yelp.com:scopeincludes a consumer scope that is enabled for your application. A scope that isn't enabled doesn't cause an error here. It's left out of the authorization (see Step 3). client_idis unknown, or the application is disabled.
Because there is no redirect, your application can't tell a canceled request from one that was never completed. Treat a request that doesn't come back as abandoned, and let the user start again.
Errors When Redeeming the Code
Get Access Token v4 errors use the OAuth 2.1 format: a string error code and an error_description.
{
"error": "invalid_grant",
"error_description": "Auth code not found or expired."
}
| HTTP Code | Error Code | Description |
|---|---|---|
| 400 - Bad Request | invalid_request | A required parameter is missing or invalid. This includes a missing code_verifier. |
| 400 - Bad Request | invalid_grant | The authorization code is unknown, expired or already used, the code_verifier doesn't match the code_challenge, or the redirect_uri doesn't match the one you sent in Step 2. |
| 400 - Bad Request | invalid_client | The client_id or client_secret is missing or wrong. |
| 400 - Bad Request | invalid_scope | The request includes a scope your application isn't allowed to use. |
| 401 - Unauthorized | invalid_client | Client authentication failed after the request included an Authorization header. Send client_id and client_secret in the form body. |
| 429 - Too Many Requests | too_many_requests | You have exceeded the rate limit. Try again later. |
| 500 - Internal Server Error | server_error | Server error. |
If the code is rejected with invalid_grant, start again from Step 1 with a new code challenge. A code can't be retried.
Errors When Calling an Endpoint
These errors use the Yelp format. They mean the access token is valid but can't be used on this endpoint:
| HTTP Code | Error Code | Description |
|---|---|---|
| 401 - Unauthorized | UNAUTHORIZED_ACCESS_TOKEN | On a business endpoint, the token doesn't have a scope the endpoint needs. This includes a consumer's access token, which never has business scopes. |
| 403 - Forbidden | MISSING_SCOPE | On a consumer endpoint, the token doesn't have a scope the endpoint needs. The description names the missing scopes, and the WWW-Authenticate header lists every scope the endpoint needs. This includes a business user's access token, which never has consumer scopes. |
| 403 - Forbidden | UNSUPPORTED_USER_TYPE | The token has the scopes the endpoint needs, but it was issued for the other kind of user. |
{
"error": {
"code": "MISSING_SCOPE",
"description": "The access token doesn't have the scopes this endpoint needs: project_actions."
}
}
Refreshing the token doesn't add scopes. To get a missing scope, send the user through the authorization page again and request it.
Get Access Token v2 and v3
Use v4 for new integrations
Some existing applications can still use v2 and v3, and they keep working as described here. We recommend moving to v4. If either endpoint returns
TOKEN_V4_REQUIRED, your application must use v4.
For these applications:
code_challengeandcode_challenge_methodare optional on the authorization request. If you sendcode_challenge, you must also sendcode_challenge_method=S256, and then send thecode_verifierwhen you redeem the code. Yelp can require PKCE for your application.redirect_uriis optional. If you leave it out, Yelp uses the default redirect URI registered for your application. Aredirect_uriyou send must be on your allowlist, and if you send one on the authorization request, send the same one when you redeem the code.- The redirect doesn't include
iss. - Access tokens expire in 7 days and refresh tokens in 365 days. See Token Lifetimes.
- Errors use the Yelp format,
{"error": {"code": ā¦, "description": ā¦}}, instead of the OAuth 2.1 format.
Business scopes and biz.yelp.com work as described in this guide. Consumer scopes and www.yelp.com are available only with the v4 rules.
Updated 8 days ago
