在 Ebay 中为订单创建发货时出错
Error Creating Shipment for an Order in Ebay
这个错误已经困扰了我大约一个星期了...我正在尝试在 Ebay 中创建货件,但在响应中收到 500 错误代码。这是文档 https://developer.ebay.com/api-docs/sell/fulfillment/resources/order/shipping_fulfillment/methods/createShippingFulfillment
的 link
我在生产环境中运行这段代码:
@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."
}]
}]}
我已支付高级开发人员支持费用,但尚未收到回复。任何帮助将不胜感激。我试过用空的 body 提交相同的请求,但这并没有改变响应。我也试过改变 headers。如果我添加 'Accept': 'application/json'
,那么我会收到 500 错误和一个空的 body。这没有任何意义。
更新
根据评论中的建议,我尝试将 params hash 更改为:
params = {
"lineItems": "[{\"lineItemId\":10025031700524,\"quantity\":1}]",
"shippedDate": "2020-05-01T08:05:00.000Z",
"shippingCarrierCode": "USPS",
"trackingNumber": "9400111899562795104724"
}
我也尝试了 运行 后续请求。我还尝试在 body 中提交以下 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
定义中使用 :
,键将被解释为符号。
Hashes
A hash is created using key-value pairs between {
and }
:
{ "a" => 1, "b" => 2 }
Both the key and value may be any object.
You can create a hash using symbol keys with the following syntax:
{ a: 1, b: 2 }
This same syntax is used for keyword arguments for a method.
Like Symbol literals, you can quote symbol keys.
{ "a 1": 1, "b #{1 + 1}": 2 }
is equal to
{ :"a 1" => 1, :"b 2" => 2 }
See Hash for the methods you may use with a hash.
要使用字符串键,请使用 =>
而不是 :
。
对你来说这意味着改变:
@header = {
'Content-Type': 'application/json',
'Authorization': "Bearer #{@token}"
}
进入:
@header = {
'Content-Type' => 'application/json',
'Authorization' => "Bearer #{@token}"
}
这个错误已经困扰了我大约一个星期了...我正在尝试在 Ebay 中创建货件,但在响应中收到 500 错误代码。这是文档 https://developer.ebay.com/api-docs/sell/fulfillment/resources/order/shipping_fulfillment/methods/createShippingFulfillment
的 link我在生产环境中运行这段代码:
@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."
}]
}]}
我已支付高级开发人员支持费用,但尚未收到回复。任何帮助将不胜感激。我试过用空的 body 提交相同的请求,但这并没有改变响应。我也试过改变 headers。如果我添加 'Accept': 'application/json'
,那么我会收到 500 错误和一个空的 body。这没有任何意义。
更新
根据评论中的建议,我尝试将 params hash 更改为:
params = {
"lineItems": "[{\"lineItemId\":10025031700524,\"quantity\":1}]",
"shippedDate": "2020-05-01T08:05:00.000Z",
"shippingCarrierCode": "USPS",
"trackingNumber": "9400111899562795104724"
}
我也尝试了 运行 后续请求。我还尝试在 body 中提交以下 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
定义中使用 :
,键将被解释为符号。
Hashes
A hash is created using key-value pairs between
{
and}
:{ "a" => 1, "b" => 2 }
Both the key and value may be any object.
You can create a hash using symbol keys with the following syntax:
{ a: 1, b: 2 }
This same syntax is used for keyword arguments for a method.
Like Symbol literals, you can quote symbol keys.
{ "a 1": 1, "b #{1 + 1}": 2 }
is equal to
{ :"a 1" => 1, :"b 2" => 2 }
See Hash for the methods you may use with a hash.
要使用字符串键,请使用 =>
而不是 :
。
对你来说这意味着改变:
@header = { 'Content-Type': 'application/json', 'Authorization': "Bearer #{@token}" }
进入:
@header = {
'Content-Type' => 'application/json',
'Authorization' => "Bearer #{@token}"
}