0

I'm trying to figure out how to send a successful request to Walmart's Update bulk inventory POST endpoint.

It's a little bit confusing since the content-type format is multipart/form-data which means that user needs to provide file. But for my use case that isn't possible since I only have a JS object to work with.

But looking at Walmart's documentation is shows an example request being sent as JSON so I've taken the below approach:

const jsonData = JSON.stringify({
        InventoryHeader: {
            version: '1.4',
        },
        Inventory: walmartData.inventory_items.reduce(
            (acc, { sku, quantity }) => {
                acc.push({
                    sku: encodeSku(sku),
                    quantity,
                });
                return acc;
            },
            [],
        ),
    });

    const data = new FormData();

    data.append('json', jsonData);

    const needleOpts = {
        headers: {
            ...data.getHeaders(),
            ...buildHeaders(), // builds auth headers 
        },
    };

    const queryObject = {
        feedType: 'inventory',
        shipNode: 'xyz,
    };

    const query = queryString.stringify(queryObject, {
        encode: false,
        arrayFormat: 'bracket',
    });

    const url = `https://sandbox.walmartapis.com/v3/feeds?${query}`;

    const result = await needle('post', url, data, needleOpts);

    return result.body;

The thing is I get back an feedId which suggests that the response is successful but when I then try to fetch the feed I get back the following error:

{
    "feedId": "3DD1DE30885E45BA8EB1CBFC94A41FEA@AQkBAQA",
    "feedStatus": "ERROR",
    "shipNode": null,
    "submittedBy": null,
    "ingestionErrors": {
        "ingestionError": [
            {
                "type": "SYSTEM_ERROR",
                "code": "PDR-0014",
                "field": null,
                "description": "INTERNAL SERVER ERROR"
            }
        ]
    },
    "itemsReceived": 0,
    "itemsSucceeded": 0,
    "itemsFailed": 0,
    "itemsProcessing": 0,
    "offset": 0,
    "limit": 50,
    "itemDetails": {
        "itemIngestionStatus": []
    },
    "additionalAttributes": null
}

In addition, when I try to fetch all inventory feeds I get back the following:

{
    "totalResults": 0,
    "offset": 0,
    "limit": 50,
    "results": {
        "feed": null
    }
}

This tells me that the inventory feed is not being created.

As far as I can tell the code I have looks okay but I can't understand why the feed isn't being created, also to note, the fact that the API is sandbox shouldn't make a difference.

Does anyone have any experience with this API and in particular sending request with JSON? Should the JSON object be in a file format?

Any ideas would be appreciated.

thexyman
  • 591
  • 1
  • 5
  • 13
  • The documentation specifies that you need you put the payload in a file and upload the file using multipart/form-data. I have added an answer so try that out and see if that works. – kushan85 May 17 '20 at 05:47

1 Answers1

0

Try this out. This is using request library, but u can try to add it in your code with minor changes.

var request = require('request');
var fs = require('fs');
var options = {
  'method': 'POST',
  'url': 'URL GOES HERE',
  'headers': {
    'WM_SVC.NAME': 'Walmart Marketplace',
    'WM_QOS.CORRELATION_ID': 'test',
    'Accept': 'application/xml',
    'WM_SEC.ACCESS_TOKEN': 'TOKEN',
    'Content-Type': 'multipart/form-data',
    'Authorization': 'Basic ....'
  },
  formData: {
    'file': {
      'value': fs.createReadStream('path/to/file'),
      'options': {
        'filename': 'inventory.xml'
      }
    }
  }
};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});
kushan85
  • 102
  • 1
  • 9
  • thanks for the response @kushan85. So my use case requires that I send the data as JSON. When I get the data into my app it is as a JS object which I then convert to JSON. atm when I send data as JSON string or even if I first write the JSON to a file and then load that file, it still doesn't seems to work. I'm currently testing on sandbox, do you know if that impacts behaviour? – thexyman May 18 '20 at 09:48
  • You are trying on sandbox ? That helps. There was an issue with sandbox inventory feeds which was fixed and pushed today, so you can try again. The sample request on developer portal is incorrect. The amount under quantity needs to be an Integer and not a string. This should work. Let me know – kushan85 May 19 '20 at 23:29
  • @thexyman were you able to send it as JSON? – ricks Jul 29 '21 at 21:20