├── .gitignore ├── LICENSE ├── README.md ├── examples └── simple.js ├── index.js ├── package.json ├── server.js └── test └── api.test.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2015 Van Nguyen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Walmart Open API 2 | ================ 3 | 4 | This library is deprecated and no longer supported. 5 | To access the latest list of Walmart Open APIs and get onboarding instructions, please visit our new portal: https://walmart.io/ 6 | 7 | ## Installation 8 | 9 | To install the library: 10 | 11 | ``` 12 | % npm install walmart --save 13 | ``` 14 | 15 | ## Usage 16 | 17 | First include the library: 18 | 19 | ``` 20 | var walmart = require('walmart')(apiKey); 21 | ``` 22 | 23 | The `apiKey` is the API key that you got from WalmartLabs when you registered. 24 | 25 | Once you have the `walmart` object you can make these requests. 26 | 27 | This is a promise based library, so requests will look like this: 28 | 29 | ``` 30 | walmart.getItem(10449075).then(function(item) { 31 | console.log(item.product.productAttributes.productName); 32 | }); 33 | ``` 34 | 35 | The `then` function is called when the item data is returned. 36 | 37 | You can see more examples in `examples/simple.js`. 38 | 39 | ### walmart.getItem(itemID) 40 | 41 | This returns the item information for a specific product based on it's WalmartLabs product ID. 42 | 43 | ### walmart.getItemByUPC(upcCode) 44 | 45 | Returns the product by the upcCode, the barcode on a product is the UPC so you should send that 46 | directly to the API. 47 | 48 | ### walmart.search(term, extras) 49 | 50 | Returns a list of products that match the search term. 51 | 52 | ### walmart.taxonomy() 53 | 54 | Returns our category taxonomy. 55 | 56 | ### recommendations(itemID) 57 | 58 | Returns recommended products based on the item ID. 59 | 60 | ### walmart.reviews(itemID) 61 | 62 | Returns customer reviews for the specific WalmartLabs Item ID. 63 | 64 | ### walmart.stores.byPosition(lat, lon) 65 | 66 | Returns a list of stores by the specified GPS latitude and longitude. 67 | 68 | ### walmart.stores.byCity(city) 69 | 70 | Returns a list of stores by the specified city name. 71 | 72 | ### walmart.stores.byZip(zip) 73 | 74 | Returns a list of stores by the specified zip code. 75 | 76 | ### walmart.stores.search(store, query, extras) 77 | 78 | Returns a list of products that match the `query` in the specified `store`. 79 | 80 | ### walmart.feeds.items(categoryId) 81 | 82 | Returns an array of items on the specified category. 83 | 84 | ### walmart.feeds.bestSellers(categoryId) 85 | 86 | Returns an array of items of the best-sellers on the specified category. 87 | 88 | ### walmart.feeds.preOrder() 89 | 90 | Returns an array of items of the available pre-orders. 91 | 92 | ### walmart.feeds.rollback(categoryId) 93 | 94 | Returns an array of items of the rollbacks on the specified category. 95 | 96 | ### walmart.feeds.clearance(categoryId) 97 | 98 | Returns an array of items of the clearance items on the specified category. 99 | 100 | ### walmart.feeds.specialBuy(categoryId) 101 | 102 | Returns an array of items of the special buy items on the specified category. 103 | 104 | ### walmart.feeds.valueOfTheDay(categoryId) 105 | 106 | Returns an array of items of the value of the day items on the specified category. 107 | 108 | ### walmart.feeds.trending(categoryId) 109 | 110 | Returns an array of items of the trending items on the specified category. 111 | -------------------------------------------------------------------------------- /examples/simple.js: -------------------------------------------------------------------------------- 1 | var walmart = require('../index.js')(process.env.WALMART_API_KEY, {protocol: 'http'}); 2 | 3 | walmart.stores.search(100, "cheerios").then(function(data) { 4 | console.log("Found " + data.count + " items"); 5 | }); 6 | 7 | walmart.getItem(10449075).then(function(item) { 8 | console.log(item.product.productName); 9 | }); 10 | 11 | walmart.getItemByUPC("041100005373").then(function(item) { 12 | console.log(item.product.productName); 13 | }); 14 | 15 | walmart.feeds.trending().then(function(data) { 16 | console.log("Trending found " + data.items.length + " items"); 17 | }); 18 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var fetch = require('isomorphic-fetch'); 2 | var Promise = require('bluebird'); 3 | 4 | function _responseToText(response) { 5 | if (response.status >= 400) throw new Error("Bad server response"); 6 | return response.text(); 7 | } 8 | 9 | function _get(options, url) { 10 | return new Promise(function (resolve, reject) { 11 | var getUrl = (options && options.protocol) ? options.protocol + ":" + url : url; 12 | fetch(getUrl).then(_responseToText).then(function(item) { 13 | resolve(JSON.parse(item)); 14 | }).catch(function(err) { 15 | reject(err); 16 | }); 17 | }); 18 | } 19 | 20 | function _feed(options, feed, key, category) { 21 | var url = "//api.walmartlabs.com/v1/feeds/" + feed + "?apiKey=" + key; 22 | if (category) { 23 | url += "&categoryId=" + category; 24 | } 25 | return _get(options, url); 26 | } 27 | 28 | module.exports = function(key, options) { 29 | return { 30 | getItem: function(itemID, terra) { 31 | if (terra) { 32 | return _get(options, "//www.walmart.com/product/terra/" + itemID); 33 | } else { 34 | return _get(options, "//www.walmart.com/product/mobile/api/" + itemID); 35 | } 36 | }, 37 | getItemByUPC: function(upcCode) { 38 | return _get(options, "//www.walmart.com/product/mobile/api/upc/" + upcCode); 39 | }, 40 | feeds: { 41 | items: function(categoryId) { 42 | return _feed(options, "items", key, categoryId); 43 | }, 44 | bestSellers: function(categoryId) { 45 | return _feed(options, "bestsellers", key, categoryId); 46 | }, 47 | preOrder: function(categoryId) { 48 | return _feed(options, "preorder", key, categoryId); 49 | }, 50 | rollback: function(categoryId) { 51 | return _feed(options, "rollback", key, categoryId); 52 | }, 53 | clearance: function(categoryId) { 54 | return _feed(options, "clearance", key, categoryId); 55 | }, 56 | specialBuy: function(categoryId) { 57 | return _feed(options, "specialbuy", key, categoryId); 58 | }, 59 | valueOfTheDay: function() { 60 | return _get(options, "//api.walmartlabs.com/v1/vod?apiKey=" + key); 61 | }, 62 | trending: function() { 63 | return _get(options, "//api.walmartlabs.com/v1/trends?apiKey=" + key + "&format=json"); 64 | } 65 | }, 66 | search: function(term, extra) { 67 | var url = "//api.walmartlabs.com/v1/search?apiKey=" + key + "&query=" + term; 68 | if (extra) { 69 | for (var k in extra) { 70 | url += "&" + k + "=" + escape(extra[k]); 71 | } 72 | } 73 | return _get(options, url); 74 | }, 75 | taxonomy: function() { 76 | return _get(options, "//api.walmartlabs.com/v1/taxonomy?apiKey=" + key); 77 | }, 78 | recommendations: function(itemID) { 79 | return _get(options, "//api.walmartlabs.com/v1/nbp?apiKey=" + key + "&itemId=" + itemID); 80 | }, 81 | reviews: function(itemID) { 82 | return _get(options, "//api.walmartlabs.com/v1/reviews/" + itemID + "?apiKey=" + key + "&format=json"); 83 | }, 84 | stores: { 85 | byPosition: function(lat, lon) { 86 | return _get(options, "//api.walmartlabs.com/v1/stores?apiKey=" + key + "&lon=" + lon + "&lat=" + lat ); 87 | }, 88 | byCity: function(city) { 89 | return _get(options, "//api.walmartlabs.com/v1/stores?apiKey=" + key + "&city=" + escape(city) ); 90 | }, 91 | byZip: function(zip) { 92 | return _get(options, "//api.walmartlabs.com/v1/stores?apiKey=" + key + "&zip=" + zip ); 93 | }, 94 | search: function(store, query, extras) { 95 | var url = "http://search.mobile.walmart.com/search?query=" + escape(query) + "&store=" + store; 96 | if (extras) { 97 | for (var k in extras) { 98 | url += "&" + k + "=" + escape(extras[k]); 99 | } 100 | } 101 | return _get({}, url); 102 | } 103 | } 104 | } 105 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "walmart", 3 | "version": "0.0.3", 4 | "description": "Walmart API wrapper", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "author": "Van Nguyen ", 10 | "contributors": [ 11 | { 12 | "name": "Jack Herrington", 13 | "email": "jherrington@walmartlabs.com" 14 | } 15 | ], 16 | "license": "MIT", 17 | "dependencies": { 18 | "bluebird": "^2.9.34", 19 | "isomorphic-fetch": "^2.1.1" 20 | }, 21 | "devDependencies": { 22 | "chai": "^1.10.0", 23 | "jshint": "^2.5.11", 24 | "mocha": "^2.1.0", 25 | "nock": "^0.56.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var app = express(); 3 | 4 | app.use(express.compress()); 5 | app.use(express.static(__dirname + '/public', { maxAge: 100 })); 6 | 7 | app.listen(process.env.PORT || 3000); 8 | -------------------------------------------------------------------------------- /test/api.test.js: -------------------------------------------------------------------------------- 1 | /*global fetch*/ 2 | "use strict"; 3 | 4 | var expect = require('chai').expect; 5 | var nock = require('nock'); 6 | var good = '{"foo":"bar"}'; 7 | var walmart = require('../index.js')('***key***'); 8 | 9 | describe('walmart', function() { 10 | it('should allow for a product get', function(done) { 11 | nock('https://www.walmart.com') 12 | .get('/product/mobile/api/2020') 13 | .reply(200, good); 14 | walmart.getItem(2020).then(function(data) { 15 | expect(data.foo).to.equal("bar"); 16 | done(); 17 | }); 18 | }); 19 | 20 | it('should allow for a product get with terra', function(done) { 21 | nock('https://www.walmart.com') 22 | .get('/product/terra/2020') 23 | .reply(200, good); 24 | walmart.getItem(2020, true).then(function(data) { 25 | expect(data.foo).to.equal("bar"); 26 | done(); 27 | }); 28 | }); 29 | 30 | it('should allow for a product get by upc', function(done) { 31 | nock('https://www.walmart.com') 32 | .get('/product/mobile/api/upc/2020') 33 | .reply(200, good); 34 | walmart.getItemByUPC(2020).then(function(data) { 35 | expect(data.foo).to.equal("bar"); 36 | done(); 37 | }); 38 | }); 39 | 40 | it('should allow for an items feed request', function(done) { 41 | nock('https://api.walmartlabs.com') 42 | .get('/v1/feeds/items?apiKey=***key***&categoryId=1234') 43 | .reply(200, good); 44 | walmart.feeds.items(1234).then(function(data) { 45 | expect(data.foo).to.equal("bar"); 46 | done(); 47 | }); 48 | }); 49 | 50 | it('should allow for an bestsellers feed request', function(done) { 51 | nock('https://api.walmartlabs.com') 52 | .get('/v1/feeds/bestsellers?apiKey=***key***&categoryId=1234') 53 | .reply(200, good); 54 | walmart.feeds.bestSellers(1234).then(function(data) { 55 | expect(data.foo).to.equal("bar"); 56 | done(); 57 | }); 58 | }); 59 | 60 | it('should allow for an preorder feed request', function(done) { 61 | nock('https://api.walmartlabs.com') 62 | .get('/v1/feeds/preorder?apiKey=***key***&categoryId=1234') 63 | .reply(200, good); 64 | walmart.feeds.preOrder(1234).then(function(data) { 65 | expect(data.foo).to.equal("bar"); 66 | done(); 67 | }); 68 | }); 69 | 70 | it('should allow for an rollback feed request', function(done) { 71 | nock('https://api.walmartlabs.com') 72 | .get('/v1/feeds/rollback?apiKey=***key***&categoryId=1234') 73 | .reply(200, good); 74 | walmart.feeds.rollback(1234).then(function(data) { 75 | expect(data.foo).to.equal("bar"); 76 | done(); 77 | }); 78 | }); 79 | 80 | it('should allow for an clearance feed request', function(done) { 81 | nock('https://api.walmartlabs.com') 82 | .get('/v1/feeds/clearance?apiKey=***key***&categoryId=1234') 83 | .reply(200, good); 84 | walmart.feeds.clearance(1234).then(function(data) { 85 | expect(data.foo).to.equal("bar"); 86 | done(); 87 | }); 88 | }); 89 | 90 | it('should allow for an specialbuy feed request', function(done) { 91 | nock('https://api.walmartlabs.com') 92 | .get('/v1/feeds/specialbuy?apiKey=***key***&categoryId=1234') 93 | .reply(200, good); 94 | walmart.feeds.specialBuy(1234).then(function(data) { 95 | expect(data.foo).to.equal("bar"); 96 | done(); 97 | }); 98 | }); 99 | 100 | it('should allow for an value of the day feed request', function(done) { 101 | nock('https://api.walmartlabs.com') 102 | .get('/v1/vod?apiKey=***key***') 103 | .reply(200, good); 104 | walmart.feeds.valueOfTheDay().then(function(data) { 105 | expect(data.foo).to.equal("bar"); 106 | done(); 107 | }); 108 | }); 109 | 110 | it('should allow for an value of the day feed request', function(done) { 111 | nock('https://api.walmartlabs.com') 112 | .get('/v1/trends?apiKey=***key***&format=json') 113 | .reply(200, good); 114 | walmart.feeds.trending().then(function(data) { 115 | expect(data.foo).to.equal("bar"); 116 | done(); 117 | }); 118 | }); 119 | 120 | it('should allow for a search request', function(done) { 121 | nock('https://api.walmartlabs.com') 122 | .get('/v1/search?apiKey=***key***&query=foo') 123 | .reply(200, good); 124 | walmart.search('foo').then(function(data) { 125 | expect(data.foo).to.equal("bar"); 126 | done(); 127 | }); 128 | }); 129 | 130 | it('should allow for a search request with facets', function(done) { 131 | nock('https://api.walmartlabs.com') 132 | .get('/v1/search?apiKey=***key***&query=foo&facets=on') 133 | .reply(200, good); 134 | walmart.search('foo', {facets: 'on'}).then(function(data) { 135 | expect(data.foo).to.equal("bar"); 136 | done(); 137 | }); 138 | }); 139 | 140 | it('should allow for a taxonomy request', function(done) { 141 | nock('https://api.walmartlabs.com') 142 | .get('/v1/taxonomy?apiKey=***key***') 143 | .reply(200, good); 144 | walmart.taxonomy().then(function(data) { 145 | expect(data.foo).to.equal("bar"); 146 | done(); 147 | }); 148 | }); 149 | 150 | it('should allow for a recommendations request', function(done) { 151 | nock('https://api.walmartlabs.com') 152 | .get('/v1/nbp?apiKey=***key***&itemId=2020') 153 | .reply(200, good); 154 | walmart.recommendations(2020).then(function(data) { 155 | expect(data.foo).to.equal("bar"); 156 | done(); 157 | }); 158 | }); 159 | 160 | it('should allow for a reviews request', function(done) { 161 | nock('https://api.walmartlabs.com') 162 | .get('/v1/reviews/2020?apiKey=***key***&format=json') 163 | .reply(200, good); 164 | walmart.reviews(2020).then(function(data) { 165 | expect(data.foo).to.equal("bar"); 166 | done(); 167 | }); 168 | }); 169 | 170 | it('should allow for a stores by position request', function(done) { 171 | nock('https://api.walmartlabs.com') 172 | .get('/v1/stores?apiKey=***key***&lon=22&lat=45') 173 | .reply(200, good); 174 | walmart.stores.byPosition(45, 22).then(function(data) { 175 | expect(data.foo).to.equal("bar"); 176 | done(); 177 | }); 178 | }); 179 | 180 | it('should allow for a stores by city request', function(done) { 181 | nock('https://api.walmartlabs.com') 182 | .get('/v1/stores?apiKey=***key***&city=houston') 183 | .reply(200, good); 184 | walmart.stores.byCity("houston").then(function(data) { 185 | expect(data.foo).to.equal("bar"); 186 | done(); 187 | }); 188 | }); 189 | 190 | it('should allow for a stores by zip request', function(done) { 191 | nock('https://api.walmartlabs.com') 192 | .get('/v1/stores?apiKey=***key***&zip=94587') 193 | .reply(200, good); 194 | walmart.stores.byZip(94587).then(function(data) { 195 | expect(data.foo).to.equal("bar"); 196 | done(); 197 | }); 198 | }); 199 | 200 | it('should allow for a store search', function(done) { 201 | nock('http://search.mobile.walmart.com') 202 | .get('/search?query=foo&store=100') 203 | .reply(200, good); 204 | walmart.stores.search(100, "foo").then(function(data) { 205 | expect(data.foo).to.equal("bar"); 206 | done(); 207 | }); 208 | }); 209 | 210 | it('should allow for a store search with extras', function(done) { 211 | nock('http://search.mobile.walmart.com') 212 | .get('/search?query=foo&store=100&fooz=baz') 213 | .reply(200, good); 214 | walmart.stores.search(100, "foo", {fooz: "baz"}).then(function(data) { 215 | expect(data.foo).to.equal("bar"); 216 | done(); 217 | }); 218 | }); 219 | }); --------------------------------------------------------------------------------