Shopping Discussion

Using the Walmart Canada API to get inventory counts

  • Last Updated:
  • Aug 20th, 2017 11:04 am
[OP]
Newbie
Apr 15, 2017
20 posts
22 upvotes

Using the Walmart Canada API to get inventory counts

I've been trying to buy the $40 PC2GO and because the online product page doesn't allow you to check in-store stocks and calling can be counterproductive (you're basically alerting a cash-strapped associate of a massively hot deal), I took a look at the Walmart API to see if I could get that info, and it turns out that yes, you can get quite a lot more details compared to the online website, especially those products where it won't allow you to check in-store stock.
So without further ado, here's how to do it:
You'll need:
-A recent version of Google Chrome
-The Advanced REST client addon
-And its sibling ARC cookie exchange

After all these items are installed, do the following:
-Open your products walmart page such as this one.
-Open F12 developer tools and click on the Network tab
-On the Walmart page, click on Buy In Store to see in-store info
-At the bottom of the first column in the Network tab, click on the item that says 'availability'
-Scroll down and open the form data panel
-Copy the value for csrfToken, for example 114dbf4787367b74f807ff6702ea4218d8a8c0de-1495049340193-c93c75f42f56c1bf529395b0
-From the Chrome Apps menu open the Advanced REST client
-At the top right ensure the option Use XHR is toggled on
-Now under request URL insert https://www.walmart.ca/ws/en/products/availability
-Select the POST option
-Select application/x-www-form-urlencoded if it's not by default
-Under raw payload insert the following: stores=["<insert store number here>","<insert store 2 number here>"]&products={"<insert walmart.ca product id here>":[{"sku":"<insert sku number here>","upc":["<insert UPC number here>"]}]}&csrfToken=<insert csrfToken you got from F12 developer tools>
-Click Send
-Under JSON (sometimes it takes a little bit or it may only show the raw result) you should see something like this:
{
"6000001842788": {
"online": [
{
"maxRegularPrice": 0,
"minRegularPrice": 0,
"pricePerUnit": "13¢/100g",
"mapPrice": 0,
"minCurrentPrice": 1.17,
"maxCurrentPrice": 1.17,
"inventory": 60,
"sku": "10174150",
"clearance": false,
"offerId": "10174150",
"limited": false,
"reducedPrice": false,
"offerType": "1P",
"limitedStock": false,
"sellerId": "0",
"rollback": false,
"date": "",
"status": "Available",
"eligible": true,
"sellerName": "Walmart",
"asAdvertised": false
}
],
"stores": [
{
"minRegularPrice": 0,
"maxRegularPrice": 0,
"minCurrentPrice": 1.27,
"maxCurrentPrice": 1.27,
"inventory": 65,
"sku": "10174150",
"clearance": false,
"limited": false,
"limitedStock": false,
"rollback": false,
"date": "",
"status": "Available",
"storeNumber": "1097",
"eligible": false,
"asAdvertised": false
},
{
"minRegularPrice": 0,
"maxRegularPrice": 0,
"minCurrentPrice": 1.27,
"maxCurrentPrice": 1.27,
"inventory": 65,
"sku": "10174150",
"clearance": false,
"limited": false,
"limitedStock": false,
"rollback": false,
"date": "",
"status": "Available",
"storeNumber": "5726",
"eligible": false,
"asAdvertised": false
},
{
"minRegularPrice": 0,
"maxRegularPrice": 0,
"minCurrentPrice": 1.27,
"maxCurrentPrice": 1.27,
"inventory": 65,
"sku": "10174150",
"clearance": false,
"limited": false,
"limitedStock": false,
"rollback": false,
"date": "",
"status": "Available",
"storeNumber": "3011",
"eligible": false,
"asAdvertised": false
},
{
"minRegularPrice": 0,
"maxRegularPrice": 0,
"minCurrentPrice": 1.27,
"maxCurrentPrice": 1.27,
"inventory": 65,
"sku": "10174150",
"clearance": false,
"limited": false,
"limitedStock": false,
"rollback": false,
"date": "",
"status": "Available",
"storeNumber": "3013",
"eligible": false,
"asAdvertised": false
}
],
"onlineSummary": {
"status": "Available",
"date": "",
"eligible": true,
"clearance": false,
"rollback": false,
"asAdvertised": false,
"limited": false,
"limitedStock": false,
"minRegularPrice": 0,
"maxRegularPrice": 0,
"minCurrentPrice": 1.17,
"maxCurrentPrice": 1.17
},
"storeSummary": {
"status": "Available",
"date": "",
"eligible": false,
"clearance": false,
"rollback": false,
"asAdvertised": false,
"limited": false,
"limitedStock": false,
"minRegularPrice": 0,
"maxRegularPrice": 0,
"minCurrentPrice": 1.27,
"maxCurrentPrice": 1.27
}
}
}
42 replies
Deal Fanatic
Jan 15, 2006
7904 posts
2043 upvotes
Richmond Hill
Don't rely on the on-hands. Walmart has a extremely archaic system and the stores info isn't real time, it is update once a day overnight.

Their whole inventory system is a joke.
Deal Addict
User avatar
Dec 25, 2012
4124 posts
2397 upvotes
Toronto
Thanks, that's very cool. Confirmed PC2GO was out of stock at my location, but I already knew that: "status": "OutOfStock",
Deal Addict
User avatar
Dec 25, 2012
4124 posts
2397 upvotes
Toronto
Made a quick and rough string formatter for the payload: http://js.do/code/152882

Just enter all the info and it will give you a raw string to input into REST, a bit less annoying then modifying it each time in text.

Code: Select all

<!DOCTYPE html>
<html>
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width">
      <title>String Formatter</title>
      <style>
         body {background-color: powderblue;}
         p {color: blue;}
      </style>
   </head>
   <body>
      <h1>String Formatter</h1>
      <form name="frm">
         <p><input type="text" id="storeNumber" value="" size="20"> Store Number</p>
         <p><input type="text" id="productID" value="" size="20"> Product ID Number (may not be needed)</p>
         <p><input type="text" id="skuNumber" value="" size="20"> SKU Number</p>
         <p><input type="text" id="upcNumber" value="" size="20"> UPC Number</p>
         <p><input type="text" id="csrfToken" value="" size="100"> csrfToken</p>
         <p><button type="button" onclick="combineFields()">Submit</button></p>
      </form>
      <script type="text/javascript">
         function combineFields() {
               
         var storeNumber = document.getElementById("storeNumber").value;
         var productID = document.getElementById("productID").value;
         var skuNumber = document.getElementById("skuNumber").value;
         var upcNumber = document.getElementById("upcNumber").value;
         var csrfToken = document.getElementById("csrfToken").value;
         document.getElementById("store").innerHTML = storeNumber;
         document.getElementById("product").innerHTML = productID;
         document.getElementById("sku").innerHTML = skuNumber;
         document.getElementById("upc").innerHTML = upcNumber;
         document.getElementById("token").innerHTML = csrfToken;
         
         }
      </script>
      <h4>Copy and Paste the string below:</h4>
      stores=["<span id="store"></span>"]&products={"<span id="product"></span>":[{"sku":"<span id="sku"></span>","upc":["<span id="upc"></span>"]}]}&csrfToken=<span id="token"></span>
   </body>
</html>
Last edited by zentro on May 17th, 2017 11:42 pm, edited 2 times in total.
[OP]
Newbie
Apr 15, 2017
20 posts
22 upvotes
zentro wrote:
May 17th, 2017 11:42 pm
Nice! Maybe in a couple weeks we end up with an unofficial Walmart client stored in Github pages, haha.
Deal Addict
User avatar
Aug 18, 2008
2393 posts
406 upvotes
Ottawa
Thanks for the detailed explanation. I learnt something new today :)

Also, for anyone that was like me and was lost, 2 key things:

- The "Buy in Stores" button is a dropdown list/button near "Add to Cart".
- "Form Data" table is actually the last set of data results in the "Headers" tab of "Availability". Expand it, and the bottom line will be csrfToken.
[OP]
Newbie
Apr 15, 2017
20 posts
22 upvotes
express.items wrote:
May 18th, 2017 12:43 pm
Anyway to get a list of store numbers?
You can search Google for your favourite stores walmart.ca page (like this one https://www.walmart.ca/en/clarenville-store/3018), under the store name you'll see a 4-digit number, that's the store number (it's also in the URL). It's also on your receipt and so on.
If you want to get the 4 stores nearest to a postal code (it's actually not very accurate IMO, rather look them up myself), go to a product page, make sure you enter the correct postal code, then click on Buy In Store, just before the csrfToken in the Network pane you'll see the list of stores.
And FYI, the walmart.ca product ID is the one that appears last in the product URL, for example walmart.ca/en/ip/great-value-dry-pasta-spagettini/6000001842788. SKU and UPC are in the bottom of the product page.
Good luck!
Deal Addict
Jul 27, 2004
2081 posts
45 upvotes
144 stores in this map:
Image

Store numbers:
"1000","1001","1004","1007","1012","1023","1029","1031","1038","1039","1041","1042","1047","1054","1056"
"1059","1060","1061","1064","1069","1072","1075","1079","1080","1081","1083","1086","1087","1095","1101"
"1107","1109","1110","1111","1115","1116","1117","1118","1120","1121","1125","1126","1130","1137","1139"
"1150","1151","1152","1153","1154","1155","1156","1157","1158","1159","1160","1161","1162","1164","1188"
"1190","1199","1200","1211","3000","3001","3005","3006","3016","3020","3031","3034","3037","3043","3045"
"3049","3050","3051","3053","3054","3055","3062","3064","3065","3066","3067","3071","3078","3082","3088"
"3096","3103","3105","3106","3110","3111","3113","3114","3115","3120","3122","3123","3125","3126","3127"
"3129","3130","3131","3133","3134","3135","3141","3142","3143","3144","3145","3152","3153","3156","3159"
"3160","3161","3164","3166","3170","3171","3172","3178","3186","3195","3197","3635","3638","3645","3649"
"3653","3654","3740","5742","5743","5752","5778","5811","5831"
Deal Addict
User avatar
Dec 25, 2012
4124 posts
2397 upvotes
Toronto
vintazh wrote:
May 18th, 2017 12:54 pm
And FYI, the walmart.ca product ID is the one that appears last in the product URL, for example walmart.ca/en/ip/great-value-dry-pasta-spagettini/6000001842788.
Interesting I was using Walmart Item # in that spot, but I guess that isn't correct despite it still providing results.

Doesn't seem like product ID is even needed, if you leave it blank it shows the same results from what I can tell.
Last edited by zentro on May 18th, 2017 5:05 pm, edited 1 time in total.
[OP]
Newbie
Apr 15, 2017
20 posts
22 upvotes
zentro wrote:
May 18th, 2017 5:05 pm
Interesting I was using Walmart Item # in that spot, but I guess that isn't correct despite it still providing results.
Yeah it may still work, in fact I'd like to see what parameters are actually optional (I can confirm csrfToken is not), and if we can get results by using the UPC or SKU numbers only, that'd be great.
Deal Addict
Aug 3, 2005
1336 posts
408 upvotes
I followed all of the instructions but for some reason, I am not getting the correct output. I am getting "Access Denied"

I've pasted this into the Advanced REST Client:
stores:["1031","1200","1190","1086"]&products:{"6000001842788":[{"sku":"10174150","upc":["60538888131"]}]}&csrfToken:9570b81021ab63bcf57a55f73dbbe444fedce2ef-1495156311281-ac6e6b7601505843c7b35e44

I've attached a screenshot of my settings. One screenshot is with "Use XHR" toggled on. The other screenshot is with "Use XHR" toggled off.
1.PNG
2.PNG

As you can see from the screenshots, I don't have a section called JSON. I only have RAW and PARSED at the bottom.
I'll Keep It Short and Sweet. Family, Religion, Friendship ... These Are the Three Demons You Must Slay if You Wish to Succeed in Business
[OP]
Newbie
Apr 15, 2017
20 posts
22 upvotes
kennyt18 wrote:
May 18th, 2017 9:47 pm
I followed all of the instructions but for some reason, I am not getting the correct output. I am getting "Access Denied"

I've pasted this into the Advanced REST Client:
stores:["1031","1200","1190","1086"]&products:{"6000001842788":[{"sku":"10174150","upc":["60538888131"]}]}&csrfToken:9570b81021ab63bcf57a55f73dbbe444fedce2ef-1495156311281-ac6e6b7601505843c7b35e44

I've attached a screenshot of my settings. One screenshot is with "Use XHR" toggled on. The other screenshot is with "Use XHR" toggled off.

1.PNG2.PNG


As you can see from the screenshots, I don't have a section called JSON. I only have RAW and PARSED at the bottom.
I think you have some syntax errors in the payload, ( : instead of = ) it should be like this:
stores=["1031","1200","1190","1086"]&products={"6000001842788":[{"sku":"10174150","upc":["60538888131"]}]}&csrfToken=9570b81021ab63bcf57a55f73dbbe444fedce2ef-1495156311281-ac6e6b7601505843c7b35e44
Deal Addict
Aug 3, 2005
1336 posts
408 upvotes
vintazh wrote:
May 18th, 2017 9:58 pm
I think you have some syntax errors in the payload, ( : instead of = ) it should be like this:
stores=["1031","1200","1190","1086"]&products={"6000001842788":[{"sku":"10174150","upc":["60538888131"]}]}&csrfToken=9570b81021ab63bcf57a55f73dbbe444fedce2ef-1495156311281-ac6e6b7601505843c7b35e44
Thanks for the reply. I just tried this exact line:

stores=["1031","1200","1190","1086"]&products={"6000001842788":[{"sku":"10174150","upc":["60538888131"]}]}&csrfToken=9570b81021ab63bcf57a55f73dbbe444fedce2ef-1495156311281-ac6e6b7601505843c7b35e44

and it still failed. I got the same "Access Denied" message as per the screenshot.
I'll Keep It Short and Sweet. Family, Religion, Friendship ... These Are the Three Demons You Must Slay if You Wish to Succeed in Business

Top