Closed doverradio closed 2 years ago
@doverradio Hi are you passing these values https://github.com/drbarzaga/walmart-mws/blob/master/src/walmart-mws.js#L5 ? I think the problem is a config problem with your host. You need to use the Walmart API URL as the host.
Ah I see I failed to put any value to replace HOST
.
What is the Walmart API URL? Can you please share it or where I can locate it?
@doverradio When you create a Developer Account in Walmart you have access to this URL in your dashboard.
Thank you for that, I was just in the "Try it now" API explorer and found this https://marketplace.walmartapis.com
.
I immediately tested this as the base url so my config is now;
var walmartMws = require("../node_modules/walmart-mws/src/walmart-msw")(
'xxxxxxxCLIENTIDxxxxxx',
'xxxxCLIENTSECRETxxxxxxxxxxxxxxxxxxxxxxxxxx',
'https://marketplace.walmartapis.com/',
'VERSION',
'NAME'
);
The result is I am still getting error:
{
"error": {
"message": "Request failed with status code 400",
"name": "Error",
"stack": "Error: Request failed with status code 400\n at createError (C:\\Users\\project\\backend\\node_modules\\walmart-mws\\node_modules\\axios\\lib\\core\\createError.js:16:15)\n at settle (C:\\Users\\project\\backend\\node_modules\\walmart-mws\\node_modules\\axios\\lib\\core\\settle.js:17:12)\n at IncomingMessage.handleStreamEnd (C:\\Users\\project\\backend\\node_modules\\walmart-mws\\node_modules\\axios\\lib\\adapters\\http.js:236:11)\n at IncomingMessage.emit (node:events:402:35)\n at IncomingMessage.emit (node:domain:475:12)\n at endReadableNT (node:internal/streams/readable:1343:12)\n at processTicksAndRejections (node:internal/process/task_queues:83:21)",
"config": {
"url": "VERSION/token",
"method": "post",
"data": "grant_type=client_credentials",
"headers": {
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
"WM_SVC.NAME": "NAME",
"WM_QOS.CORRELATION_ID": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
"Authorization": "Basic xxxxxxxxxxxxxxxxxxxxxxxxxx",
"User-Agent": "axios/0.19.2",
"Content-Length": 29
},
"baseURL": "https://marketplace.walmartapis.com/",
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1
}
}
}
I feel really close to solving this but still not yet there. I did not put any value for VERSION
. Could this be the cause of the error?
@doverradio The problem is that you are using the wrong URL https://marketplace.walmartapis.com/ the host is another no this.
Ok, I'm totally lost then.
Upon viewing the Walmart Developer Portal items guide, I find they give an example endpoint like so:
https://marketplace.walmartapis.com/v3/feeds?feedType=MP_ITEM_MATCH
Their direct Bulk Item Setup (Multiple) instructions are not providing any url as well.
I am continuing to search further for the correct url but, if you know it, please can you share it? I am willing to try anything at this point because I have around 340,000 items I am trying to post.
@doverradio Ok no problem.
Please see screenshot:
It really does seem they are pushing that url on me: https://marketplace.walmartapis.com/
Solved it!
Here's my final code which generated a valid access_token:
// using express.js, this is a single controller method...
exports.walmartApiGetToken = async ( req, res ) => {
try {
let endpoint = `https://marketplace.walmartapis.com/v3/token`
let headers = {
Accept: "application/json",
"Content-Type": "application/x-www-form-urlencoded",
Authorization: `Basic ${Buffer.from(
`${ CLIENT_ID` }:${ `CLIENT_SECRET` }`
).toString('base64')}`,
"WM_QOS.CORRELATION_ID": uuidv4(),
"WM_SVC.NAME": "Walmart Marketplace",
}
let method = `POST`
let body = new URLSearchParams();
body.append('grant_type', 'client_credentials');
let result = await fetch( endpoint, { method, headers, body } )
result = await result.json()
console.log( `result...`, result )
res.json(result)
} catch ( e ) { console.log( `Got an error in walmartApiGetToken...`, e ); res.json( { error: e } ) }
}
Got the result...
{
"access_token": "XXXXXXXXXXXXXXXXSUPERLONGACCESSTOKENXXXXXXXXXXXXXXXXXXXXXX",
"token_type": "Bearer",
"expires_in": 900
}
@doverradio Cool!
My code (portions are taken from your example):
So, after running that, I got the following error...
What am I doing wrong?