使用Swift访问Shippo API返回未记录的错误

时间:2017-12-17 20:14:17

标签: json swift alamofire swifty-json shippo

我们正在尝试使用Shippo API来打印运输标签,但似乎无法使其运行。此处代码中使用的数据直接来自Shippo网站。

我们正在使用Swift,Alamofire和SwiftyJSON与我们的ios App中的Swift代码,并得到此错误结果:

{
"detail" : "Shippo API could not process your request. Request ID: 8af7a4c883cd453bb492ad2782bd54d3"
}

我们搜索过Shippo网站,stackoverflow和Google,但找不到任何对此错误的引用。

这是Swift代码:

func shippoRequest() {

var headers: HTTPHeaders = [
"content-type": "application/json"
]

let credentials = "shippo_test_318550b6ebde57479ef555ae7f80e660c23ee6c6"
headers["Authorization"] = "ShippoToken \(credentials)"
let parameters: [String: Any] = [
"address_from": [
[
"name" : "Shippy Shipper",
"company": "Our Shippo App",
"street1" : "101 Lafayette Road",
"street2" : "",
"city" : "Rye",
"state" : "NH",
"zip" : "03870",
"phone" : "8443872777",
"country" : "US",
"email" : "cuzineed1@yahoo.com"
]
],
"address_to": [
[
"name": "Mrs. Hippo",
"street1": "965 Mission St.",
"city": "San Francisco",
"state": "CA",
"zip": "94103",
"country": "US",
"phone": "0987654321",
"email": "support@goshippo.com"
]
],
"async": false,
"parcels": [
[
"length": "5",
"width": "5",
"height": "5",
"distance_unit": "in",
"weight": "2",
"mass_unit": "lb"
]
]
]
let url = "https://api.goshippo.com/shipments"

Alamofire.request(url, method: .post, parameters: parameters , encoding: JSONEncoding.default, headers: headers)
.responseJSON { (response) in
switch response.result {
case .success(let value):
let swiftyJson = JSON(value)
print ("return as JSON using swiftyJson is: \(swiftyJson)")
case .failure(let error):
print ("error: \(error)")
}

}
}

我们已经尝试了许多不同的地址,包括来往和使用shippo网站上的相同数据,使用测试链接,它确实有效。

如果Shippo返回此错误,我们希望之前有人会看到它,或者Shippo应该能够解释哪些无效数据会产生此错误。

非常感谢任何帮助。

谢谢

1 个答案:

答案 0 :(得分:0)

我相信地址到/来自字段的“object_purpose”属性。这在API的“2017-03-29”版本中已弃用,因此可能取决于您是否使用旧版本的API。

https://goshippo.com/docs/changelog