在eBay中为订单创建发货时出错
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在eBay中为订单创建发货时出错相关的知识,希望对你有一定的参考价值。
此错误使我困扰了大约一个星期...我试图在Ebay中创建货件,但响应中出现500错误代码。这是文档https://developer.ebay.com/api-docs/sell/fulfillment/resources/order/shipping_fulfillment/methods/createShippingFulfillment
的链接我正在生产环境中运行此代码:
@header =
'Content-Type': 'application/json',
'Authorization': "Bearer #@token"
uri = URI.parse("https://api.ebay.com/sell/fulfillment/v1/order/#order.order_number/shipping_fulfillment")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
items = []
order.items.each do |i|
items << "lineItemId": i[:id]
end
params =
"lineItems": items,
"shippedDate": Time.parse(date).strftime("%Y-%m-%dT%H:%M:%S.000Z"),
"shippingCarrierCode": "USPS",
"trackingNumber": tracking_number
request = Net::HTTP::Post.new(uri.request_uri, @header)
request.body = params.to_json
response = http.request(request)
puts response.code #prints 500
我的错误:
"errors": [
"errorId": 2003,
"domain": "ACCESS",
"category": "APPLICATION",
"message": "Internal error",
"longMessage": "There was a problem with an eBay internal system or process. Contact eBay developer support for assistance",
"parameters": [
"name": "reason",
"value": "Failed to transform underlying error response, see logs."
]
]
我已支付了高级开发人员支持的费用,但尚未收到回复。任何帮助将不胜感激。我尝试用空的正文提交相同的请求,但这不会更改响应。我也尝试过更改标题。如果我添加'Accept': 'application/json'
,那么我会得到一个500的错误,一个空的正文。这没有任何意义。
UPDATE
根据评论中的建议,我尝试将params哈希更改为:
params =
"lineItems": "[\"lineItemId\":10025031700524,\"quantity\":1]",
"shippedDate": "2020-05-01T08:05:00.000Z",
"shippingCarrierCode": "USPS",
"trackingNumber": "9400111899562795104724"
我也尝试过运行后续请求。我也尝试过在体内提交以下JSON:
request.body =
"lineItems": [
"lineItemId": "10025031700524",
"quantity": "1"
],
"shippedDate": "2020-05-01T08:05:00.000Z",
"shippingCarrierCode": "USPS",
"trackingNumber": "9400111899562795104724"
.to_json
这些尝试中的每一个都会产生与以前完全相同的错误。我也尝试过将数量更改为整数和字符串。
UPDATE 2
这是我的要求的内容:
POST /sell/fulfillment/v1/order/24-04954-08727/shipping_fulfillment
content-type: application/json
authorization: Bearer v#i^1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=
accept-encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
accept: */*
user-agent: Ruby
connection: close
host: api.ebay.com
content-length: 159
content-type: application/x-www-form-urlencoded
"lineItems":["lineItemId":"10025031700524"],"shippedDate":"2020-05- 01T08:05:00.000Z","shippingCarrierCode":"USPS","trackingNumber":"9400111899562795104724"
在请求内容中:
POST /sell/fulfillment/v1/order/24-04954-08727/shipping_fulfillment content-type: application/json authorization: Bearer v#i^1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX= accept-encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3 accept: */* user-agent: Ruby connection: close host: api.ebay.com content-length: 159 content-type: application/x-www-form-urlencoded "lineItems":["lineItemId":"10025031700524"],"shippedDate":"2020-05- 01T08:05:00.000Z","shippingCarrierCode":"USPS","trackingNumber":"9400111899562795104724"
我发现content-type
出现了两次。
在irb中运行了一些示例之后,看来net/http
库适用于字符串,而不适用于符号。通过在:
定义中使用@header
,按键将被解释为符号。
foo: 'bar'
# is a short-hand for
:foo => 'bar'
# in the same vein
'foo': 'bar'
# is a short-hand for
:'foo' => 'bar'
以上示例产生的密钥为symbol。
要使用字符串作为键,您必须使用不带=>
的:
。
'foo': 'bar'
#=> :foo=>"bar" (symbol keys)
'foo' => 'bar'
#=> "foo"=>"bar" (string keys)
对您而言,这意味着改变:
@header = 'Content-Type': 'application/json', 'Authorization': "Bearer #@token"
进入:
@header =
'Content-Type': 'application/json',
'Authorization': "Bearer #@token"
以上是关于在eBay中为订单创建发货时出错的主要内容,如果未能解决你的问题,请参考以下文章
在 WooCommerce 中为特定用户角色创建订单时添加额外的客户注释