I am getting a 404 from the Walmart Canada Maketplace API when bulk feeding new item

Viewed 270

I am able to GET data from Walmart Canada Marketplace API, using Nodejs, but I am unable to post a new item with their bulk feed endpoint. I get back a 404 'bad request'. I am not sure if the error is in the POST request or in the JSON. I am also not sure if Walmart Canada really accepts JSON files or just claims to.

Here is my code:

import { createSign, randomBytes } from 'crypto'
import fetch from 'node-fetch';
import { resolve } from 'url';
import fs from 'fs';


const method = 'post';

const BASE_URL = 'https://marketplace.walmartapis.com/'

const PK_HEADER = '\n-----BEGIN PRIVATE KEY-----\n'
const PK_FOOTER = '\n-----END PRIVATE KEY-----\n'

const WALMART_CONSUMER =  "consumer";
const WALMART_CHANNEL = 'channel';
const WALMART_SECRET = 'secret';


function generateCorrelationId () {
  return randomBytes(16).toString('hex')
}

function 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 url = resolve(BASE_URL, "/v3/ca/feeds?feedType=item")

  const timestamp = Date.now()
  const signature = generateSignature(url, method, timestamp)

  const headers = {
    'WM_SVC.NAME': 'Walmart Marketplace',
    '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,
    'WM_TENANT_ID' : 'WALMART.CA',
    'WM_LOCALE_ID' : 'en_CA',
    'Accept': 'application/xml',
    'Content-Type': 'multipart/form-data'

  }

  fetch(url, {
    method: method,
    headers: headers,
    formData: {
        'file': {
          'value': fs.createReadStream('wm_new_item.json'),
          'options': {
            'filename': 'wm_new_item.json'
          }
        }
      }
  })
  .then(response => console.log(response))
  .catch(function (error) {
    console.log(error)
  });

and here is my json file:

{
"MPItemFeedHeader":{
   "subset":"INTERNAL",
   "mart":"WALMART_CA",
   "sellingChannel":"marketplace",
   "subCategory":"toys_other",
   "locale":"en",
   "version":"3.2",
   "requestId": "1606485958",
   "requestBatchId": "1606485958",
   "processMode":"REPLACE"
},
"MPItem":[
   {
      "Orderable":{
         "sku":"2663d9467e64a0a94ab0eeeccd9f37dd",
         "productIdentifiers":{
            "productIdType":"UPC",
            "productId":"078257310609"
         },
         "productName":"abc",
         "brand":"abc",
         "price":1.00,
         "fulfillmentLagTime":6,
         "floorPrice":1.00,
         "startDate":"2021-04-20T08:37:30Z",
         "endDate":"2021-04-20T08:37:30Z",
         "ProductIdUpdate":"No",
         "SkuUpdate":"No",
         "ShippingWeight":1
      },
      "Visible":{
         "Toys":{
            "shortDescription":"abc",
            "mainImageUrl":"https://images-na.ssl-images-amazon.com/images/I/71X4z76HUTS._AC_SL1500_.jpg",
            "productSecondaryImageURL":[
               "https://images-na.ssl-images-amazon.com/images/I/71X4z76HUTS._AC_SL1500_.jpg",
               "https://images-na.ssl-images-amazon.com/images/I/71X4z76HUTS._AC_SL1500_.jpg"
            ],
            "msrp":1.00,
            "variantGroupId":"abc",
            "variantAttributeNames":[
               "color"
            ],
            "isPrimaryVariant":"Yes"

         }
      }
   }
]

}

Thanks!

1 Answers

I figured it out with the help of this answer on another question.

You are better off referencing this than Walmarts official documentation

You need to submit a post request to the "https://marketplace.walmartapis.com/v3/feeds endpoint appending your type on the url ?feedType=[something]

You need to make sure that your "Content-Type" is "application/json" if you are sending them JSON.

You do not need to send it multipart like the documentation suggests, just send your entire JSON file as the body and it should work correctly.

Related