这个错误已经困扰我大约一周了。。。我正试图在易趣上创建一个发货,但我在响应中收到了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错误,其中有一个空的正文。这没有任何意义。
更新
根据评论中的建议,我尝试将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
每一次尝试都会产生与以前完全相同的错误。我试着把这个量改成一个整数&字符串。
更新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
定义中包含:
,键被解释为符号。
引用Ruby文档:
哈希
使用
{
和}
:之间的键值对创建哈希{ "a" => 1, "b" => 2 }
键和值都可以是任何对象。
您可以使用以下语法的符号键创建哈希:
{ a: 1, b: 2 }
同样的语法用于方法的关键字参数。
与符号文字一样,您可以引用符号键。
{ "a 1": 1, "b #{1 + 1}": 2 }
等于
{ :"a 1" => 1, :"b 2" => 2 }
请参阅哈希,了解可以用于哈希的方法。
要使用字符串键,请使用=>
而不是:
。
对你来说,这意味着改变:
@header = { 'Content-Type': 'application/json', 'Authorization': "Bearer #{@token}" }
进入:
@header = {
'Content-Type' => 'application/json',
'Authorization' => "Bearer #{@token}"
}