2

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!

dave_dev
  • 75
  • 6
  • I'm having the same issue, i am sending JSON but they keep returning an error saying i have an invalid character as if they are parsing XML. Their docs and examples show JSON but it seems like their feed endpoint does not take a JSON payload. – ricks Jul 30 '21 at 13:33

1 Answers1

0

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.

ricks
  • 3,154
  • 31
  • 51
  • Thanks Rick. Did your solution work for Walmart CA or Walmart US? Seller Support at Walmart CA just got back to me that CA does not accept JSON. – dave_dev Jul 30 '21 at 16:08
  • @dave_dev i was trying in US, i guess i assumed they would be the same in both marketplaces, i would give it a shot if its not too much work and the docs say it supported. Good luck! – ricks Jul 30 '21 at 17:34
  • @dave_dev did you ever get a feed successfully submitted? – ricks Aug 02 '21 at 20:18
  • Thanks for asking. I changed my code to XML and I am using FormData() and Buffer(), which are making the file POST to Walmart. However, the feed fails once it gets to Walmart. I believe it has something to do with how Buffer.from() is parsing the file. Any ideas? – dave_dev Aug 02 '21 at 20:37
  • @dave_dev to be honest i'm stuck as well, I've spent at least 16 hours trying to successfully submit a feed that uploads an item to Walmart without success. The feeds either error out with no message or they stay pending for 24 hours before they are marked as failed with no error message. I even logged the network traffic from when adding an item via their UI and submitted the exact same payload and it just gets stuck processing and eventually fails. I'm trying to get in contact with any developer at Walmart right now because I'm convinced there is something wrong with their endpoint. – ricks Aug 02 '21 at 21:07
  • Are you successfully submitted the feed and getting a feedid returned or is your feed submissions still failing? – ricks Aug 02 '21 at 21:09
  • Yes. I reached out to Walmart to get the content of the uploaded file but it takes forever to get a response from the development team. Quite frustrating. – dave_dev Aug 02 '21 at 21:15
  • I believe my issue was POSTing the form data as a binary. Did you parse your file as binary? – dave_dev Aug 04 '21 at 05:40
  • @dave_dev no i am sending the data as a a string that can be parsed to JSON, they keep telling me the payload is invalid even when i copy paste the payloads in their example. I'm patiently waiting for their support to get back to me – ricks Aug 04 '21 at 13:27