Skip to content

Commit

Permalink
itemSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
freshlogic committed Mar 17, 2024
1 parent 3f2bde9 commit 02e73ad
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
47 changes: 47 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,53 @@ function WalmartMarketplace(args) {
return finalize(err, null, callback);
}
},
/**
* The Item Search API allows you to query the Walmart.com global product catalog by item keyword, UPC or GTIN.
* @see https://developer.walmart.com/api/us/mp/items#operation/getSearchResult
* @param {Object} [options]
* @param {String} [options.gtin] Specifies a Global Trade Item Number (GTIN) search. GTIN must be 14 digits.
* @param {String} [options.query] Specifies a keyword search as a String.
* @param {String} [options.upc] Specifies a Universal Product Code (UPC) search. UPC must be 12 digits.
* @param {String} [options['WM_QOS.CORRELATION_ID']] A unique ID which identifies each API call and used to track and debug issues. Defaults to a random UUID.
*/
itemSearch: async function(options, callback) {
try {
// Options are optional
if (!options) {
options = {};
} else if (typeof options === 'function') {
callback = options;
options = {};
}

const queryParameters = new URLSearchParams();

['gtin', 'query', 'upc'].forEach(key => {
if (Object.hasOwn(options, key)) {
queryParameters.set(key, options[key]);
}
});

const url = `${_options.url}/v3/items/walmart/search?${queryParameters.toString()}`;

const response = await fetch(url, {
headers: {
Accept: 'application/json',
'WM_QOS.CORRELATION_ID': options['WM_QOS.CORRELATION_ID'] || crypto.randomUUID(),
'WM_SEC.ACCESS_TOKEN': (await _this.authentication.getAccessToken()).access_token,
'WM_SVC.NAME': _options['WM_SVC.NAME']
}
});

if (!response.ok) {
throw new Error(response.statusText, { cause: response });
}

return finalize(null, await response.json(), callback);
} catch(err) {
return finalize(err, null, callback);
}
},
/**
* Completely deactivates and un-publishes an item from the site.
* @see https://developer.walmart.com/api/us/mp/items#operation/retireAnItem
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls",
"test": "node --test"
},
"version": "1.3.0"
"version": "1.3.1"
}

0 comments on commit 02e73ad

Please sign in to comment.