2

I am breaking my head trying to upload a feed to walmart, after many times trying i used postman to generate C# restsharp code for me, in postman it works, but when using the c# restsharp code it returns a mysterious error. like this: "No message body writer has been found for response class FeedAcknowledgement"

what does that mean?

here is my code:

 string requestUrl = "";
        requestUrl = string.Format("https://marketplace.walmartapis.com/v2/feeds?feedType=inventory");

        string method = "POST";

        // string[] sig = getSig(method, requestUrl).Replace("\r", "").Split('\n');

        var mySig = new Signature(ConsumerID, SecretKEY, requestUrl, method);
        var s = mySig.TimeStamp;
        var returendSigniture = mySig.GetSignature(s);

        var client = new RestClient("https://marketplace.walmartapis.com/v2/feeds?feedType=inventory");
        var request = new RestRequest(Method.POST);
        //request.AddHeader("postman-token", "c325ba5f-813a-f990-7899-6bfc4b14aa1b");
        request.AddHeader("cache-control", "no-cache");
        request.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
        request.AddHeader("accept", "application/xml");
        request.AddHeader("wm_consumer.id", "--");
        request.AddHeader("wm_sec.auth_signature", returendSigniture);
        request.AddHeader("wm_sec.timestamp", mySig.TimeStamp);
        request.AddHeader("wm_qos.correlation_id", "123456abcdef");
        request.AddHeader("wm_svc.name", "Walmart Marketplace");
        request.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"BOUNDERY\"\r\n\r\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<wm:inventory xmlns:wm=\"http://walmart.com/\">\n  <wm:sku>PP00500-2PC</wm:sku>\n  <wm:quantity>\n    <wm:unit>EACH</wm:unit>\n    <wm:amount>120</wm:amount>\n  </wm:quantity>\n  <wm:fulfillmentLagTime>1</wm:fulfillmentLagTime>\n</wm:inventory>\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
        IRestResponse response = client.Execute(request);
4

2 回答 2

0

我花了一整天的时间研究如何申请 Walmart v3。我建议你采取以下两个步骤:

  1. 使用Walmart 签名者以生成签名令牌。
  2. 您将需要使用 HttpWebRequest 以类似于此处描述的方式从 Walmart 获取响应。
于 2017-05-25T09:29:06.310 回答
0

我无法让它在 C# 中本地工作,但我确实有一个解决方法。

Java SDK 可以成功地向 Walmart 提交多部分请求。我围绕 SDK 函数编写了一个包装器,它可以接受基本的命令行输入来读取文本文件并发送带有附件的适当调用。从这里,您可以从您的 C# 程序调用 .jar 文件(我通过动态生成的批处理文件来完成)并通过文本文件接收响应。This is a sub-optimal system, but it works reliably and when the choice was between updating inventory on 2000 items every day and using some dirty code, I went with the Java wrapper method. 这将在 C# SDK 出来后立即被替换,但我相信这是 C# SDK 可能会延迟的原因之一。

仅在花了大约一周的时间尝试使边界/流/附件在 C# 中工作并且成功率为零之后,才使用了此解决方案。案例也提交给了沃尔玛,我能够与他们的一些顶级工程支持人员一起工作,这个问题完全难倒了他们。我能够一直跟踪 Java SDK 的执行,一直到构建 Web 请求的内置 Maven / Java 函数,因此 Java 正在处理一个在 C# 中无法立即明确的多部分请求。 .

于 2017-08-01T15:55:12.417 回答