-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Canada support #83
Comments
Hi @mendeljacks - Interesting issue that I had not even anticipated. Our Market is As you pointed out the APIs are different. In fact, they have different schemas altogether. If you look at the Additionally, it looks like each
Mexico would be an easier market to implement currently as it uses the same authentication and authorization schemas, with relatively small header additions, but Canada is a completely different story. I'm not sure how quickly we will get around to implementing Canada as it is certainly not a priority at the moment, but I will definitely make a branch and explore some ideas. |
I figured out how to authenticate with only using nodejs and the built in crypto library: import axios from 'axios'
import { createSign, randomBytes } from 'crypto'
const PK_HEADER = '\n-----BEGIN PRIVATE KEY-----\n'
const PK_FOOTER = '\n-----END PRIVATE KEY-----\n'
const BASE_URL = 'https://marketplace.walmartapis.com'
const WALMART_CONSUMER = '***'
const WALMART_SECRET = '***'
const WALMART_CHANNEL = '***'
const generateCorrelationId = () => {
return randomBytes(16).toString('hex')
}
const generateSignature = (url, method, timestamp) => {
const privateKey = `${PK_HEADER}${WALMART_SECRET}${PK_FOOTER}`
const stringToSign =
WALMART_CONSUMER + '\n' + url + '\n' + method.toUpperCase() + '\n' + timestamp + '\n'
const sign = createSign('RSA-SHA256')
sign.update(stringToSign)
return sign.sign(privateKey, 'base64')
}
const doRequest = async (endpoint, method, body = {}) => {
const url = BASE_URL + endpoint
const timestamp = Date.now()
const signature = generateSignature(url, method, timestamp)
const headers = {
'WM_SVC.NAME': 'Walmart Gateway API',
'WM_CONSUMER.ID': WALMART_CONSUMER,
'WM_SEC.TIMESTAMP': timestamp,
'WM_SEC.AUTH_SIGNATURE': signature,
'WM_QOS.CORRELATION_ID': generateCorrelationId(),
'WM_CONSUMER.CHANNEL.TYPE': WALMART_CHANNEL,
...(method === 'post' ? { accept: 'application/json' } : {})
}
const response = await axios({
method: method,
url: url,
data: body,
headers: headers
}).catch(err => {
console.log(err?.response?.data)
debugger
})
debugger
}
// Get a specific sku
doRequest('/v3/ca/items/2298', 'get')
// Update inventory
const sku = '2298'
const body = JSON.stringify({
InventoryHeader: {
version: '1.4'
},
Inventory: [
{
sku: 'test1',
quantity: {
unit: 'EACH',
amount: 10
}
},
{
sku: '894728',
quantity: {
unit: 'EACH',
amount: 20
}
}
]
})
doRequest(`/v3/ca/feeds?feedType=inventory`, 'post', { file: Buffer.from(body) }) |
When using the walmart canada marketplace api, the routes need to be modified to include the 'ca' part.
eg /v3/ca/feeds instead of /v3/feeds.
Options I considered:
I would prefer option 1 since the apis are not exactly the same (eg no multi-node shipping support in canada)
ps.
I vibe with the philosophy of this package,
thanks for the great work
The text was updated successfully, but these errors were encountered: