Walmart API - 有效负载mime类型问题 - 批量创建/更新项目无效 [英] Walmart API - payload mime type issue - bulk create/update items not working

查看:492
本文介绍了Walmart API - 有效负载mime类型问题 - 批量创建/更新项目无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够成功地对其他Walmart API端点进行API调用(特别是GET请求端点),但是批量项端点(POST请求)会导致错误,即使我似乎一切都正确。

I am able to make API calls to other Walmart API endpoints successfully (specifically the GET request endpoints), but the bulk items endpoint (a POST request) results in an errors, even though I seem to have everything correct.

以下是对该端点的引用
https://developer.walmartapis.com/#bulk-createupdate-items

Here is the reference to that endpoint https://developer.walmartapis.com/#bulk-createupdate-items

HTTP响应元信息

500内部服务器错误

500 Internal Server Error

xml

HTTP响应

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:errors xmlns:ns2="http://walmart.com/">
    <ns2:error>
        <ns2:code>SYSTEM_ERROR.GMP_GATEWAY_API</ns2:code>
        <ns2:description>Couldn't determine the boundary from the message!</ns2:description>
        <ns2:info>System encountered some internal error.</ns2:info>
        <ns2:severity>ERROR</ns2:severity>
        <ns2:category>DATA</ns2:category>
        <ns2:causes/>
        <ns2:errorIdentifiers/>
    </ns2:error>
</ns2:errors>

HTTP请求:

url
https:// marketplace.walmartapis.com/v2/feeds?feedType=item

方法 POST

请求标题

WM_SVC.NAME: Walmart Marketplace
WM_CONSUMER.ID: {my consumer id key}
WM_QOS.CORRELATION_ID: {my arbitrary text key}
Content-Type: multipart/form-data
Accept: application/xml
WM_SEC.AUTH_SIGNATURE:{my jar-file-generated key}
WM_SEC.TIMESTAMP:{my jar-file-generated timestamp}

POST有效负载(只是文本,参数没有键)

<?xml version="1.0" encoding="UTF-8"?>
<MPItemFeed xmlns="http://walmart.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://walmart.com/ MPItem.xsd ">
  <MPItemFeedHeader>
    <version>2.1</version>
    <requestId>qqq</requestId>
    <requestBatchId>qqq1</requestBatchId>
  </MPItemFeedHeader>
  <MPItem>
    <sku>qqq</sku>
    <Product>
      <productName>QQQ 1-Foot S-Video Male to 2 S-Video Female Y Cable (CSV2F)</productName>
      <longDescription><![CDATA[<div class="productDescriptionWrapper"> QVS Premium S-Video Mini4 Male to Two Female Splitter Cable CSV2F A/V Device Cables <div class="emptyClear">
      </div>
      </div>]]></longDescription>
      <shelfDescription><![CDATA[QVS 1-Foot S-Video Male to 2 S-Video Female Y Cable (CSV2F)]]></shelfDescription>
      <shortDescription>QQQ 1-Foot S-Video Male to 2 S-Video Female Y Cable (CSV2F)</shortDescription>
      <mainImage>
        <mainImageUrl>http://images.antonline.com/img-main/500/037229400328.jpg</mainImageUrl>
      </mainImage>
      <productIdentifiers>
        <productIdentifier>
          <productIdType>Item ID</productIdType>
          <productId>46817049</productId>
        </productIdentifier>
      </productIdentifiers>
      <productTaxCode>2038710</productTaxCode>
      <Electronics>
        <brand>QQQ</brand>
        <ElectronicsCables>
        </ElectronicsCables>
      </Electronics>
    </Product>
    <price>
      <currency>USD</currency>
      <amount>12.34</amount>
    </price>
    <shippingWeight>
      <value>1.234</value>
      <unit>LB</unit>
    </shippingWeight>
  </MPItem>
</MPItemFeed>






注意:

我在发出http请求时尝试使用Google的高级REST客户端应用程序以及POSTMAN,以排除源自我的代码的问题。

I tried using Google' Advanced REST Client Application as well as POSTMAN when making http requests, in order to rule out issues stemming from my code.

我已经尝试过调整想到的一切。

I've tried tweaking everything that came to mind.

我让其他端点有GET请求工作,所以我知道它不是身份验证,IP,防火墙或其他任何问题。

I got other endpoints having GET requests to work, so I know it's not an issue with authentication, IP, firewall, or anything like that.

我知道由walmart提供的jar文件生成的凭据(请参阅
身份验证部分文档 https://developer.walmartapis.com/#jar-executable-recommended)必须喂你发送的网址。所以我知道这不是用jar文件生成错误密钥的问题。

I know the credentials generated by the jar file provided by walmart (see the authentication section of the documention https://developer.walmartapis.com/#jar-executable-recommended ) has to be fed the url you're sending to. So I know it's not an issue of generating the wrong key with the jar file.

HYPOTHESES:


  • 根据回复,我发送的数据或标题肯定有问题。


无法确定消息的边界!

Couldn't determine the boundary from the message!

听起来像xml没有平衡标签,但我已经验证了这个xml

sounds like the xml is doesn't have balanced tags, but I've validated this xml


  • 沃尔玛api此端点的文档说使用标头 Content-Type:multipart / form-data; 。所以我做了,导致失败响应。

  • The walmart api documentation for this endpoint says to use the header Content-Type: multipart/form-data;. So I did, results in the failure response.

但是使用这个标题对我来说似乎没有意义,因为有效载荷body是一个xml字符串。不应该是 Content-Type:application / xml ?我也试过这个,但上面的响应失败却失败了(500,SYSTEM_ERROR.GMP_GATEWAY_API,无法确定消息的边界!)

But using this header doesn't seem to make sense to me, since the payload body is an xml string. Shouldn't it be Content-Type: application/xml? I tried this too, but it failed with the failed response above (500, SYSTEM_ERROR.GMP_GATEWAY_API, Couldn't determine the boundary from the message!)

所以看来 Content-Type:application / xml 可以排除。


  • walmart api文档仅举例说明如何更改产品ID或sku,而不是创建。我假设我只是省略了特定于更新产品ID或sku的xml标签,但xml有效负载也会产生500响应。



我没有想法,有没有其他人获得批量创建/更新项目上班?
任何人都有实际有效的示例代码吗?

I'm out of ideas, has anyone else gotten bulk create/update items to work? Anyone have example code that actually works?

推荐答案

如果有人使用PHP绊倒这个并且仍然遇到问题即使尝试了OP的解决方案(例如 500 响应消息无法确定消息的边界!系统遇到一些内部错误,您可以使用cURL自动处理边界,方法是将 CURLOPT_POSTFIELDS 作为数组传递,如下所示:

In case anyone is stumbling across this using PHP and still having trouble even after trying OP's solution (e.g. 500 response with message "Couldn't determine the boundary from the message!" or "System encountered some internal error", you can use cURL to automatically handle the boundary for you by passing CURLOPT_POSTFIELDS as an array, like so:

curl_setopt($c, CURLOPT_POSTFIELDS, ['file' => $xml]);

这篇关于Walmart API - 有效负载mime类型问题 - 批量创建/更新项目无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆