如何解决沃尔玛上的批量项目设置端点不使用 JSON
我正在尝试按照此 guide 和此 api documentation
向 Walmarts API 提交供稿在他们的指南中说
使用 XML 或 JSON 格式的有效负载向 Walmart 发送项目提要
我正在发送这个 JSON
{
"MPItemFeedHeader":{
"version":"1.0","sellingChannel":"mpsetupbymatch","locale":"en"
},"MPItem":[
{
"Item":{
"productIdentifiers":{
"productId":"042666047173","productIdType":"UPC"
},"ShippingWeight":2,"price":420.69,"sku":"RICKS-12345"
}
}
]
}
通过像这样的 POST 请求:
# Submits a Feed to Walmart
# @param Feed_data [Hash] data that will be submited with the Feed
# @param type [String] Enum: "item" "RETIRE_ITEM" "MP_ITEM" "MP_WFS_ITEM" "MP_ITEM_MATCH" "MP_MAINTENANCE" "SKU_TEMPLATE_MAP" "SHIPPING_OVERRIDES"
def submit_Feed(Feed_data,type)
# To add a param to a multipart POST request you need to append the params to the URL
endpoint = "https://marketplace.walmartapis.com/v3/Feeds?FeedType=" + type
headers = self.api_client.headers.with_indifferent_access
uri = URI(endpoint)
request = Net::HTTP::Post.new(uri)
# Add required Headers
request['Authorization'] = headers["Authorization"]
request['WM_SEC.ACCESS_TOKEN'] = headers["WM_SEC.ACCESS_TOKEN"]
request['WM_QOS.CORRELATION_ID'] = headers["WM_QOS.CORRELATION_ID"]
request['WM_SVC.NAME'] = headers["WM_SVC.NAME"]
request['Accept'] = headers["Accept"]
# Set form wants an array of arrays,basically the first item is the key and the second the value
request.set_form([["file",Feed_data]],'multipart/form-data')
response = Net::HTTP.start(uri.hostname,uri.port,use_ssl: true) do |http|
http.request(request)
end
end
Feed 成功提交,但当我检查状态时,这是响应:
{
"FeedId":"6DCFAA97311140358D6D842488B24333@AQMBCgA","FeedStatus":"ERROR","shipNode":null,"submittedBy":null,"FeedSubmissionDate":1627595359155,"ingestionErrors":{
"ingestionError":[
{
"type":"DATA_ERROR","code":"ERR_EXT_DATA_0801001","field":"IB","description":"Unexpected character '{' (code 123) in prolog; expected '\u003c'\n at [row,col {unkNown-source}]: [1,1]"
}
]
},"itemsReceived":0,"itemsSucceeded":0,"itemsFailed":0,"itemsProcessing":0,"offset":0,"limit":50,"itemDetails":{
"itemIngestionStatus":[
]
},"additionalAttributes":null
}
根据错误信息判断
prolog 中出现意外字符 '{'(代码 123);预期 '\u003c'\n 在 [row,1]
似乎他们希望我发送一个 XML 文件,我不知道我做错了什么。
他们要求将数据作为多部分发送,因此我无法将 Content-Type
设置为 application/json
解决方法
我在另一个问题的 this answer 的帮助下想通了。
您最好参考 this 而非 Walmarts 官方文档
您需要向 "https://marketplace.walmartapis.com/v3/feeds
端点提交一个发布请求,并将您的类型附加到 url ?feedType=[something]
如果您向他们发送 JSON,您需要确保您的 "Content-Type"
是 "application/json"
。
您不需要像文档建议的那样多部分发送它,只需将整个 JSON 文件作为正文发送即可。
这是我用来完成这项工作的新 ruby 代码:
# Submits a feed to Walmart
# @param feed_data [Hash] data that will be submited with the feed
# @param type [String] Enum: "item" "RETIRE_ITEM" "MP_ITEM" "MP_WFS_ITEM" "MP_ITEM_MATCH" "MP_MAINTENANCE" "SKU_TEMPLATE_MAP" "SHIPPING_OVERRIDES"
def submit_feed(feed_data,type)
# To add a param to a multipart POST request you need to append the params to the URL
endpoint = "https://marketplace.walmartapis.com/v3/feeds?feedType=" + type
uri = URI.parse(endpoint)
http = Net::HTTP.new(uri.host,uri.port)
http.use_ssl = true
http.post(uri.path,feed_data,self.api_client.headers)
end
如果 Walmart 的某个人正在研究这个问题,请改进您的文档。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。