Upload feed to Walmart the feed is created but get an error "Can not find any valid inventory in Feed."

436 Views Asked by At

Uploading an inventory feed to Walmart using C# creates the feed and the feed id is returned in the response but the feed has error "Can not find any valid inventory in Feed.". When I try the upload using Postman the feed goes through with no errir. I copied the C# code from Postman into my program and I get the same results. Walmart support has been of no help. Any suggestions has to what could be wrong?

Here is my the code from Postman, essentially looks like the code I was using before I tried Postman:

RestClient client = new RestClient("https://marketplace.walmartapis.com/v3/feeds?feedType=inventory&shipNode=<myshipnode>");
RestRequest request = new RestRequest(Method.POST);
client.Timeout = -1;

request.AddHeader("Content-Type", "multipart/form-data");
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Accept", "application/json");
request.AddHeader("Accept-Encoding", "*");
request.AddHeader("Connection", "keep-alive");
request.AddHeader("WM_SEC.ACCESS_TOKEN", this.Credentials.Token);
request.AddHeader("WM_CONSUMER.CHANNEL.TYPE", System.Guid.NewGuid().ToString());
request.AddHeader("WM_QOS.CORRELATION_ID", this.Credentials.ConsumerId) ;
request.AddHeader("WM_SVC.NAME", "Walmart Marketplace");
request.AddHeader("Authorization", "Basic " + this.Credentials.Authorization);
request.AddFile("file", "c:\\temp\\file.json", "multipart/form-data");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

JSON I am sending:

{
    "InventoryHeader": {
        "version": "1.4"
    },
    "Inventory": [
        {
            "sku": "X27A001-A",
            "quantity": {
                "unit": "EACH",
                "amount": 89
            }
        }
    ]
}

Walmart sample JSON:

{
  "InventoryHeader": {
    "version": "1.4"
  },
  "Inventory": [
    {
      "sku": "test1",
      "quantity": {
        "unit": "EACH",
        "amount": 10
      }
    },
    {
      "sku": "894728",
      "quantity": {
        "unit": "EACH",
        "amount": 20
      }
    }
  ]
}
1

There are 1 best solutions below

1
On

As Greg pointed out Content-Type should be application/json. I removed the AddFile() and replace it with

request.AddParameter("file", File.ReadAllText("c:\\temp\\file.json"), "multipart/form-data", ParameterType.RequestBody);