In Wix API, you can get inventory variants using Postman based on inventory item ID.
Today, Beehexa will show you how to do it in this article.
If this is the first time you make a call in the Postman, you must generate API credentials from the Wix Developers website.
Step 1: Generate API credentials from the Wix Developers’ Website.
Follow the process in Wix API: How to get an access token and refresh the access token? To know how to access Wix API.
- After creating an app, remember the access token and the refresh token to send requests in the Postman.
Step 2: Refresh the access token using Postman.
Wix’s access token is only valid for 5 minutes, so you need to use the refresh token to request a new access token.
Flowing the steps below for refreshing the access token.
- Log in to your Postman and create a new workspace.
- Create a new POST with this URL:
https://www.wix.com/oauth/access
Code language: JavaScript (javascript)
In the body section, enter the code.
Payload:
{
"grant_type": "refresh_token",
"client_id": <APP_ID>,
"client_secret": <APP_SECRET>,
"refresh_token": <REFRESH_TOKEN>
}
Code language: JSON / JSON with Comments (json)
Body Params:
NAME | TYPE | DESCRIPTION |
grant_type | string | Value must be set to โrefresh_tokenโ |
client_id | string | The App ID as defined in the Wix Developers Center |
client_secret | string | The Secret Key for your app as defined in your Wix Developers Center |
refresh_token | string | The refresh token issued with the access token |
- Then click SEND
Response:
The Postman will return the new access token
Step 3: Get inventory variants using Postman
Before getting inventory variants, we will get the product’s inventory item ID because that parameter is included in the next call. To have the inventory item ID we must get the product.
- From Wix dashboard
- Go to โStore productsโ
- Click on โProductsโ
- Then click on the product that you want to get the product ID. In this case, I will choose this T-Shirt.
- Finally, copy the product ID in the URL.
We will rely on the product ID to get the product.
Product ID: 61ea866c-1564-401d-aa5e-1a2fc1bf28ed
Now we will get the product
- Log in to your Postman and create a new workspace.
- Create a new GET with this URL:
https://www.wixapis.com/stores/v1/products/61ea866c-1564-401d-aa5e-1a2fc1bf28ed
Code language: JavaScript (javascript)
{id} = Product ID.
-HEADER: ‘Authorization: <ACCESS TOKEN>’
Click Send
Response:
- As you can see, the Postman returned the result like this. Remember to copy this ID for the next step.
Inventory Item ID: 9e157993-ea9b-bfe2-55a1-e5d03e40d712
Finally, we will get inventory variants using Postman.
- In Postman, create a new workspace.
- Create a new POST with this URL:
https://www.wixapis.com/stores/v2/inventoryItems/9e157993-ea9b-bfe2-55a1-e5d03e40d712/getVariants
Code language: JavaScript (javascript)
{inventoryId}: inventory item ID
-HEADER: ‘Authorization: <ACCESS TOKEN>’
In the body, enter the code.
Payload:
{} }
Code language: CSS (css)
- Click Send
Response:
{
"inventoryItem": {
"id": "9e157993-ea9b-bfe2-55a1-e5d03e40d712",
"externalId": "61ea866c-1564-401d-aa5e-1a2fc1bf28ed",
"productId": "61ea866c-1564-401d-aa5e-1a2fc1bf28ed",
"trackQuantity": false,
"variants": [{
"variantId": "8f68e87a-ce96-4db4-96d5-b7f363f04249",
"inStock": true,
"availableForPreorder": false
},
{
"variantId": "d22f3a71-cff2-4591-b022-a6f7118db9fd",
"inStock": true,
"availableForPreorder": false
},
{
"variantId": "57536a3a-ba7a-41fe-aeff-5a03733b4b43",
"inStock": true,
"availableForPreorder": false
},
{
"variantId": "d2ba149d-2386-4e31-b5af-38711bc73581",
"inStock": true,
"availableForPreorder": false
},
{
"variantId": "a4e40e55-d5c1-4e29-82fe-9dc5dd230212",
"inStock": true,
"availableForPreorder": false
},
{
"variantId": "0555e721-9155-405e-a680-d7656cf872d2",
"inStock": true,
"availableForPreorder": false
},
{
"variantId": "20837ac4-39be-4e97-a754-642095a58d64",
"inStock": true,
"availableForPreorder": false
},
{
"variantId": "3fc02e16-8a7c-4588-99dd-199921b62cfd",
"inStock": true,
"availableForPreorder": false
}
],
"lastUpdated": "2022-08-31T14:23:13.563Z",
"numericId": "1654705207181000",
"preorderInfo": {
"enabled": false
}
}
}
Code language: JSON / JSON with Comments (json)
As you can see, the Postman returned all inventory variants of the product.
The above are steps to get inventory variants using Postman with Wix API. The next article will explore Wix rest API and multiple ways to make API calls.
If you have any questions, let us know in the comment below or refer to our Wix API documentation.
These steps will be shown visually in the infographic below.
Or you can watch this video for more overview.
Hopefully, you can do it!