Retrieve your API access_token (option two)
Before you can make API calls, you will need to retrieve your API access_token
. There are two methods to retrieve your access_token
.
1. Token API in Postman
- Fork the Authentication API on Postman.
- Add your
clientID
andclientSecret
as variables. - Set up the Authentication to use Basic Auth with your
clientID
andclientSecret
as the Username and Password (respectively). - Set the POST Token API to “Inherit auth from parent”.
- Call the Post Token API. The response will have your
access_token
. - (Optional) Under the Scripts tab, you could add the script below to the Post-response section to automatically update your
access_token
and add it as an Environment Variable every time you call the Post Token API. By default, the variable is named, “token
”. You could change the name to something of your choice.
tests["STATUS"] = responseCode.code === 200 var response = JSON.parse(responseBody); pm.environment.set("token", response.access_token);
2. Command Line
The access_token
is generated by the Token API with a Base64 (utf-8, Unix newline separators) encoding of your client ID and client secret.
-
Call the Token API with a Base64 (utf-8, Unix newline separators) encoding of your client ID and client secret to generate the
access_token
. The encoded string is used for the Authorization header parameter.
Note: You can use many different online and offline tools to create the encoded key. However, we highly recommend you use an offline script. The client ID and client secrets are highly confidential information. You can use the Python script below to safely encode your key offline. Swap out the placeholders, “” and “” with your actual values.
import base64; encoded_string= base64.b64encode("<client-ID>:<client-secret>".encode('utf-8')); print(encoded_string)
-
Use the Python command below to call the Token API and retrieve your
access_token
. Swap out<randomly-generated-GUID>
with a randomly generated GUID.python -m pip install requests import requests url = "https://marketplace.walmartapis.com/v3/token" payload = { "grant_type": "client_credentials" } headers = { "accept": "application/json", "Authorization": "Basic <encoded_string>", "Content-Type": "application/x-www-form-urlencoded", "WM_QOS.CORRELATION_ID": "<randomly-generated-GUID>", "WM_SVC.NAME": "Walmart Marketplace" } access_token= requests.post(url, data=payload, headers=headers) print(access_token.text)
With your access_token
, you can use it to make API calls with the other APIs offered by the Walmart Marketplace team. You will use the access_token
for the WM_SEC.ACCESS_TOKEN
header parameter (send the parameter with this format: Basic access_token
) for all other API calls.
You could also use the APIs Try it Out environment to learn how to use the Token API and other APIs too.
A few of the frequently used APIs are listed below:
You can review the other APIs in the Marketplace Developer Portal.
Updated about 10 hours ago