OAuth 2.0 authorization
Get access tokens from the Authorization API with the client_credentials, authorization_code and refresh_token grants.
Every Marketplace API call needs an OAuth 2.0 access token. You get tokens from one operation, Create an access token:
POST https://marketplace.walmart.com/seller/v4/auth/tokenIn sandbox, use https://sandbox.marketplace.walmart.com/seller/v4/auth/token. Note that the Authorization API's server is .../seller, while every other API's server is .../seller/v1.
Choose a grant type
grant_type | Who uses it | What you send |
|---|---|---|
client_credentials | Sellers calling the APIs for their own account (seller-direct) | Client authentication |
authorization_code | Solution Providers acting for a seller (delegated) | code, plus PKCE code_verifier, or confidential-client authentication and redirect_uri |
refresh_token | Solution Providers renewing delegated access | refresh_token; public clients also send client_id |
The request body is always form-encoded (Content-Type: application/x-www-form-urlencoded) and the response is JSON.
Authenticate your client
A confidential client (one that can keep a Client Secret on a server) authenticates in one of two ways:
- HTTP Basic: send
Authorization: Basic <base64(client_id:client_secret)>and leaveclient_idandclient_secretout of the body. client_secret_post: sendclient_idandclient_secretas form fields.
Use only one method. A request that combines HTTP Basic with credentials in the body returns 400 with invalid_request.
A public client (for example a desktop or mobile app) sends no client secret. Public clients that use the authorization_code grant must use PKCE.
Seller-direct access: client_credentials
Use this grant when you call the APIs for your own seller account.
curl -X POST "https://marketplace.walmart.com/seller/v4/auth/token" \
-u "$WALMART_CLIENT_ID:$WALMART_CLIENT_SECRET" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json" \
-H "x-o-tenant: WALMART_US" \
-d "grant_type=client_credentials"Or, with client_secret_post:
curl -X POST "https://marketplace.walmart.com/seller/v4/auth/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json" \
-d "grant_type=client_credentials" \
-d "client_id=$WALMART_CLIENT_ID" \
-d "client_secret=$WALMART_CLIENT_SECRET"The client_credentials grant returns an access token without a refresh token. When the token expires, request a new one the same way. You can send scope, but it doesn't reduce the access provisioned for your client, and the response doesn't echo it. See API scopes.
Delegated access: authorization_code with PKCE
Solution Provider apps use this grant after a seller approves the app.
- Create a PKCE
code_verifier: a random string of 43 to 128 characters fromA-Z,a-z,0-9,-,.,_and~. - Derive the
code_challengefrom it with theS256method. Theplainmethod isn't accepted. - Send the seller to Walmart Account Login at
https://login.account.wal-mart.com/authorizewith yourcode_challenge. To receive a refresh token, request theoffline_accessscope. - After the seller approves, Walmart returns an authorization
codeto your app. - Exchange the code for tokens:
curl -X POST "https://marketplace.walmart.com/seller/v4/auth/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json" \
-d "grant_type=authorization_code" \
-d "code=$AUTHORIZATION_CODE" \
-d "code_verifier=$CODE_VERIFIER" \
-d "client_id=$WALMART_CLIENT_ID"A public client must send code_verifier. A confidential client can omit code_verifier if it authenticates at the token operation and sends redirect_uri:
curl -X POST "https://marketplace.walmart.com/seller/v4/auth/token" \
-u "$WALMART_CLIENT_ID:$WALMART_CLIENT_SECRET" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json" \
-d "grant_type=authorization_code" \
-d "code=$AUTHORIZATION_CODE" \
-d "redirect_uri=https://app.example.com/walmart/callback"PKCE is recommended for all clients, including confidential ones.
Renew delegated access: refresh_token
When offline_access was granted, the token response includes a refresh_token. Use it to get a new access token without asking the seller to sign in again:
curl -X POST "https://marketplace.walmart.com/seller/v4/auth/token" \
-u "$WALMART_CLIENT_ID:$WALMART_CLIENT_SECRET" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json" \
-d "grant_type=refresh_token" \
-d "refresh_token=$REFRESH_TOKEN"Public clients send client_id in the body instead of authenticating. If you send scope, it must not exceed the scope originally granted.
Token response
{
"access_token": "<access_token>",
"token_type": "Bearer",
"expires_in": 900,
"refresh_token": "<refresh_token>"
}| Field | Always present | Description |
|---|---|---|
access_token | Yes | Opaque Bearer access token. |
token_type | Yes | Always Bearer. |
expires_in | Yes | Access token lifetime, in seconds. |
refresh_token | No | Returned for delegated authorization when offline_access was granted. |
scope | No | Space-delimited scopes granted for delegated authorization. Present when the delegated scope is narrowed from the original grant. |
Optional fields are left out when they don't apply. They're never sent as null.
Select a market with x-o-tenant
The optional x-o-tenant header selects the market the token is issued for. Send exactly one value. Comma-separated values are rejected.
| Value | Market |
|---|---|
WALMART_US | Walmart US |
WALMART_CA | Walmart Canada |
WALMART_MX | Walmart Mexico |
WALMART_CL | Walmart Chile |
- A direct client that's active in more than one market must send
x-o-tenant. - A direct client with exactly one active market uses that market when the header is left out.
- For a delegated token, the market comes from the seller's authorization. If you send
x-o-tenant, it must match.
Use the token
Send the access token on every Marketplace API request:
GET /v4/orders HTTP/1.1
Host: marketplace.walmart.com
Authorization: Bearer <access_token>
Accept: application/jsonDon't use WM_SEC.ACCESS_TOKEN
The V4 APIs accept the access token only in the Authorization: Bearer header. Don't send it as WM_SEC.ACCESS_TOKEN.
Errors
Token errors return a JSON body with an error code, and may include error_description and error_uri:
{
"error": "invalid_request",
"error_description": "<description of the problem>"
}| Status | When it happens |
|---|---|
400 | The token request is invalid. For example, combining HTTP Basic with credentials in the body returns invalid_request. |
401 | Client authentication failed. The response includes a WWW-Authenticate header, for example Basic realm="seller-api". |
429 | The request exceeded the applicable rate limit. |
500 | An unexpected server error occurred. error is server_error. |
502 | A service the token endpoint depends on is temporarily unavailable. error is temporarily_unavailable. Retry the request. |
The error field is one of these codes:
error | What to check |
|---|---|
invalid_request | A required parameter is missing, or the request is malformed. |
invalid_client | Your Client ID or Client Secret. |
invalid_grant | The authorization code, PKCE verifier or refresh token. |
unauthorized_client | Whether your client may use this grant type. |
unsupported_grant_type | grant_type is one of client_credentials, authorization_code or refresh_token. |
invalid_scope | The requested scope. On a refresh, it must not exceed the original grant. |
MARKETPLACE_AMBIGUOUS | The market. If your client is active in more than one market, send x-o-tenant. |
server_error | Nothing on your side. Retry later. |
temporarily_unavailable | Nothing on your side. Retry the request. |
Best practices
- Cache tokens. Reuse an access token until shortly before
expires_inruns out, rather than requesting a new token for every call. - Keep secrets out of logs. Treat access tokens, refresh tokens and client secrets as sensitive values. Don't log them.
- Store refresh tokens securely. A refresh token gives long-lived access to a seller's account.
- Use one client authentication method per request.
