c# - Walmart API POST failing with 400 Bad Request (inventory feed) ARCA -


i having problems post request walmart marketplace api bulk data exchange , hoping help.

background: have been successful in writing signature authentication routines, , can execute commands such products etc. indicates me authentication signatures formatted, , headers (for part) correct.

problem: receiving 400 bad request response, request content invalid. response when attempting submit test feed walmarts api. have read problem common, have yet find forum post explains actual problem, or how fix it. here current parameters:

arca arca rest client chrome

url:

https://marketplace.walmartapis.com/v2/feeds?feedtype=inventory 

headers:

accept: application/xml wm_svc.name: walmart marketplace wm_consumer.id: <consumer id> wm_sec.auth_signature: <good auth signature> wm_qos.correlation_id: 15649814651 wm_sec.timestamp: <timestamp> wm_consumer.channel.type: <channel type> content-type: multipart/form-data 

file attachment (not raw payload although has been tried)

<?xml version="1.0" encoding="utf-8"?> <inventoryfeed xmlns="http://walmart.com/">   <inventoryheader>     <version>1.4</version>   </inventoryheader>   <inventory>     <sku>kon04418</sku>     <quantity>       <unit>each</unit>       <amount>4</amount>     </quantity>     <fulfillmentlagtime>1</fulfillmentlagtime>   </inventory> </inventoryfeed> 

when take exact same xml , test @ walmart api explorer file accepted response code 200 (ok).

i have validated notepad++ xml tools plugin xml conforms xsd provided walmart. have seen numerous posts regarding boundaries need applied, have additionally attempted change content-type, , add boundaries have been unsuccessful in getting request accepted.

any in getting request return response code 200 appreciated.

lastly, once request validates in arca, implementing in c#. have of code written, there's bit of fuzziness how add attachment httpwebrequest vs. submitting raw data stream. if clarity provided on difference again, appreciate it.

so answer isn't clean , elegant, more of work around anything. have spoken few individuals inside walmart engineering team , have been told c# sdk should forthcoming in next few months.

after of research, appears there tricks how submit multi-part form walmart , system inflexible. i've seen posts adding formatted boundaries body of http request, had no such luck. unable attach body file, or data stream request.

the work around pretty simple, , ugly unfortunately. takes bit of setup, can create .jar wrapper around walmart java sdk , call .net program.

so.. steps in process:

  • grab appropriate .xsd files , generate c# classes them.
  • build formatted xml inventory file. make sure include namespaces!! walmart fail particular calls if don't include appropriate ns2 / ns3 namespaces.
  • dynamically generate batch file call java module. spawning command line process directly seemed make things cranky reason opted batch file instead.

        string path = @directory.getparent(environment.currentdirectory).tostring();      if (file.exists(@"../inventory.bat"))     {         file.delete(@"../inventory.bat");     }      string batchcommand = @"cd " + path + environment.newline + @"java -jar walmartwrapper.jar submitinventoryfeed inventoryfeed.xml";     file.writealltext(path + @"\\inventory.bat", batchcommand);      processstartinfo info = new processstartinfo();     info.useshellexecute = true;     info.filename = @"inventory.bat";     info.workingdirectory = path;     var p = process.start(info);     p.waitforexit();` 
  • from here, java module takes over. took bit of hacking around make work more sdk , less sample program.. here's of sample code making things work..

  • entry point

    if ("submitinventoryfeed".equals(args[0].trim())) {     if (args.length < 2)      {         system.out.println("need second argument submitinventoryfeed");         return;     }     string filename = args[1];     feed inventoryfeed = new feed();     try      {         inventoryfeed.submitinventoryfeed(filename);     } catch (exception ex) {         system.out.println("submitinventoryfeed failed: " + ex.getmessage());     } } 
  • sdk call (this bare bones of submitinventoryfeed without error checking)

    string path = paths.get(".").toabsolutepath().normalize().tostring(); file itemfile = filehandler.getfile(filename.trim()); string filepath = path + "\\" + "marketplaceclientconfig.properties"; walmartmarketplace wm = utils.getclient(filepath); response response = wm.submitfeed(marketplacefeedtype.inventory, itemfile); 
  • you can use responsechecker.isresponse200(response, true) test successful submissions

  • use feedacknowledgement ack = response.readentity(feedacknowledgement.class); grab actual response check errors

i first can't wait replace work around c# sdk pending walmart, time being, way have been able submit. i've looked through walmart code in depth, unfortunately, there java magic happening under hood file attachment there's not way gain access exact procedure , reverse engineer c#. think knew java inside , out figure out, have enough java background allow me cobble workable, albeit ugly solution.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -