Walmart API - 有效载荷 mime 类型问题 - 批量 create/update 项无法正常工作

Walmart API - payload mime type issue - bulk create/update items not working

我能够成功地对其他沃尔玛 API 端点进行 API 调用(特别是 GET 请求端点),但是大宗商品端点(POST 请求)导致一个错误,即使我似乎一切都正确。

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


HTTP 响应元信息

500 内部服务器错误

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

请求headers

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,以排除由我的代码引起的问题。

我已经尝试调整想到的所有内容。

我有其他端点有 GET 请求可以工作,所以我知道这不是身份验证、IP、防火墙或类似问题。

我知道 walmart 提供的 jar 文件生成的凭据(参见 文档 https://developer.walmartapis.com/#jar-executable-recommended 的身份验证部分)必须提供给您要发送到的 url。所以我知道这不是使用 jar 文件生成错误密钥的问题。


假设:

Couldn't determine the boundary from the message!

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

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

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

我没主意了,有没有其他人得到大量 create/update 项目来工作? 有人有实际工作的示例代码吗?

问题是它需要一个 HTTP 请求边界。

由于 mime 类型是 multipart/form-data,它需要一些东西:

  1. header 行应该是 Content-Type: multipart/form-data; boundary=qwerty,其中 qwerty 是您选择的任意字符串。
  2. 有效负载body需要以--qwerty开始,以--qwerty--
  3. 结束

万一有人使用 PHP 遇到这个问题,并且即使在尝试 OP 的解决方案后仍然遇到问题(例如 500 响应消息“Couldn '根据消息确定边界!”或“系统遇到一些内部错误”,您可以使用 cURL 通过传递 [=11] 自动为您处理边界=] 作为一个数组,像这样:

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

这是工作请求的示例:

POST /v2/feeds?feedType=inventory
Content-Length: 750
Content-Type: multipart/form-data; boundary=72c4c966adda8bba2e0b3ebc3176cc0c395dd8c8
Host: marketplace.walmartapis.com
Accept: application/xml
Accept-Encoding: gzip, deflate, br
User-Agent: <...>
Accept-Language: en-US
WM_CONSUMER.CHANNEL.TYPE: <...>
WM_CONSUMER.ID: <...>
WM_SEC.TIMESTAMP: <...>
WM_SEC.AUTH_SIGNATURE: <...>
WM_SVC.NAME: Walmart Marketplace
WM_QOS.CORRELATION_ID: <...>

--72c4c966adda8bba2e0b3ebc3176cc0c395dd8c8
Content-Disposition: form-data; name="xml"
Content-Length: 591

<?xml version="1.0" encoding="UTF-8"?>
<InventoryFeed xmlns="http://walmart.com/">
  <InventoryHeader>
    <version>1.4</version>
  </InventoryHeader>
  <inventory>
    <sku>sku</sku>
    <quantity>
      <unit>EACH</unit>
      <amount>1</amount>
    </quantity>
    <fulfillmentLagTime>5</fulfillmentLagTime>
  </inventory>
</InventoryFeed>

--72c4c966adda8bba2e0b3ebc3176cc0c395dd8c8--

选择你的任意字符串让我们说 arbString 例如abcdefghijklmnop(任何不应在您的 XML 正文中重复的字符串)

创建您的 XML 批量 price/inventory 负载(文件输入流)。 将您的有效负载转换为字符串 FileString = Ioutils.toString("FIS",standardCharacterset.UTF_8) .

现在追加"--arbString/n/n"+FileString+"/n--arbString--"

我通过以这种方式格式化我的负载解决了这个问题:

 $eol = "\r\n";
$data = '';

$mime_boundary="12345";

$data .= '--' . $mime_boundary . $eol;
$data .= '<?xml version="1.0"?>' . $eol . $eol;
$data .= '<MPItemFeed xmlns="http://walmart.com/">' . $eol;
$data .= '<MPItemFeedHeader>' . $eol;
$data .= '<version>2.1</version>' . $eol;
$data .= '<mart>WALMART_US</mart>' . $eol;
// $data .= '<locale>en_US</locale>' . $eol;
$data .= '</MPItemFeedHeader>' . $eol;



$data .= '<MPItem>' . $eol;
$data .= '<sku>UHP-8224-JH</sku>' . $eol;
$data .= '<productIdentifiers>' . $eol;
$data .= '<productIdentifier>' . $eol;
$data .= '<productIdType>UPC</productIdType>' . $eol;
$data .= '<productId>849849004721</productId>' . $eol;
$data .= '</productIdentifier>' . $eol;
$data .= '</productIdentifiers>' . $eol;
$data .= '<MPProduct>' . $eol;
$data .= '<productName>295 / 30 R 22 103Y  ANTARES MAJORIS M5  30 K MILES </productName>' . $eol;
$data .= '<ProductIdUpdate>No</ProductIdUpdate>' . $eol;
// $data .= '<SkuUpdate>No</SkuUpdate>' . $eol;
$data .= '<category>' . $eol;
$data .= '<Vehicle>' . $eol;
//$data .= '<Vehicle>' . $eol;
$data .= '<shortDescription>295 / 30 R 22 103Y  ANTARES MAJORIS M5  30 K MILES</shortDescription>' . $eol;
$data .= '<brand>ANTARES</brand>' . $eol;
$data .= '<mainImageUrl>https://www.stuff4crafts.com/media/catalog/product/4/3/437764.jpg</mainImageUrl>' . $eol;
$data .= '<tireSize>2255516</tireSize>' . $eol;
$data .= '</Vehicle>' . $eol;
//$data .= '</Vehicle>' . $eol;
$data .= '</category>' . $eol;
$data .= '</MPProduct>' . $eol;
$data .= '<MPOffer>' . $eol;
$data .= '<price>203.99</price>' . $eol;
$data .= '<MinimumAdvertisedPrice>203.99</MinimumAdvertisedPrice>' . $eol;
$data .= '<ShippingWeight>' . $eol;
$data .= '<measure>0.8000</measure>' . $eol;
$data .= '<unit>lb</unit>' . $eol;
$data .= '</ShippingWeight>' . $eol;
$data .= '</MPOffer>' . $eol;
$data .= '</MPItem>' . $eol;



$data .= '</MPItemFeed>' . $eol;

$data .= "--" . $mime_boundary . "--" . $eol . $eol; // finish with two eol's!!