我一直在使用UPS api来获取包裹的费用估算值,并且可以使用JSON(在普通包裹上)进行估算,并使用链接https://wwwcie.ups.com/rest/Rate
获得良好的响应。我也想使用运费估算,并且已经实施了格式正确的请求,直接从开发者文档中获取。我使用的链接是完全相同的方式,但包含运费选项。 https://wwwcie.ups.com/rest/FreightRate
这些都是测试链接。当我使用货运请求时,出现如下错误:
{
"Fault":{
"faultcode":"Client",
"faultstring":"An exception has been raised as a result of client data.",
"detail":{
"Errors":{
"ErrorDetail":{
"Severity":"Hard",
"PrimaryErrorCode":{
"Code":"10002",
"Description":"The XML document is well formed but the document is not valid"
}
}
}
}
}
}
要了解我发送的内容(同样,直接从开发人员文档中复制出来) 这就是请求的样子
{
"UPSSecurity": {
"UsernameToken": {
"Username": "myName",
"Password": "thePassword"
},
"ServiceAccessToken": {
"AccessLicenseNumber": "RemovedForStackOverflowButItIsCorrect"
}
},
"FreightRateRequest": {
"ShipFrom": {
"Name": "Test US Shipper",
"Address": {
"AddressLine": "123 Lane",
"City": "TIMONIUM",
"StateProvinceCode": "MD",
"PostalCode": "21093",
"CountryCode": "US",
"ResidentialAddressIndicator": ""
},
"AttentionName": "Test Shipper",
"Phone": {
"Number": "4444444444",
"Extension": "4444"
},
"EMailAddress": "gcc0htq@ups.com"
},
"ShipperNumber": "AT0123",
"ShipTo": {
"Name": "Dilbert\u0027s Derbies",
"Address": {
"AddressLine": "555 Main St",
"City": "LOUISVILLE",
"StateProvinceCode": "KY",
"PostalCode": "40201",
"CountryCode": "US"
},
"AttentionName": "Dilbert",
"Phone": {
"Number": "8459865555"
}
},
"PaymentInformation": {
"Payer": {
"Name": "Test US Shipper",
"Address": {
"AddressLine": "123 Lane",
"City": "LUTHERVILLE TIMONIUM",
"StateProvinceCode": "MD",
"PostalCode": "21093",
"CountryCode": "US"
},
"ShipperNumber": "AT0123",
"AccountType": "1",
"AttentionName": "Test Shipper",
"Phone": {
"Number": "4444444444",
"Extension": "4444"
},
"EMailAddress": "gcc0htq@ups.com"
},
"ShipmentBillingOption": {
"Code": "10"
}
},
"Service": {
"Code": "308"
},
"Commodity": {
"Description": "FRS-Freight",
"Weight": {
"UnitOfMeasurement": {
"Code": "LBS"
},
"Value": "150"
},
"Dimensions": {
"UnitOfMeasurement": {
"Code": "IN",
"Description": " "
},
"Length": "9",
"Width": "5",
"Height": "4"
},
"NumberOfPieces": "1",
"PackagingType": {
"Code": "PLT"
},
"FreightClass": "60"
},
"DensityEligibleIndicator": "",
"AlternateRateOptions": {
"Code": "3"
},
"PickupRequest": {
"PickupDate": "20191123"
},
"GFPOptions": {
"GPFAccesorialRateIndicator": ""
},
"TimeInTransitIndicator": ""
}
}
答案 0 :(得分:0)
因此,事实证明api文档已过时,在联系UPS之后,他们给了我有关所需结构的信息。就是这样:
{
"UPSSecurity":{
"UsernameToken":{
"Username":"Username",
"Password":"Password"
},
"ServiceAccessToken":{
"AccessLicenseNumber":"AccessLicenseNumber"
}
},
"FreightRateRequest":{
"Request":{
"RequestOption":"1",
"TransactionReference":{
"TransactionIdentifier":"TransactionIdentifier"
}
},
"ShipFrom":{
"Name":"ShipFrom Name",
"Address":{
"AddressLine":"AddressLine",
"City":"City",
"StateProvinceCode":"StateProvinceCode",
"PostalCode":"PostalCode",
"CountryCode":"CountryCode"
},
"AttentionName":"Contact",
"Phone":{
"Number":"Phone number",
"Extension":"Extension number"
},
"EMailAddress":"EMailAddress"
},
"ShipperNumber":"ShipperNumber",
"ShipTo":{
"Name":"ShipTo name",
"Address":{
"AddressLine":"AddressLine",
"City":"City",
"StateProvinceCode":"StateProvinceCode",
"PostalCode":"PostalCode",
"CountryCode":"CountryCode"
},
"AttentionName":"AttentionName",
"Phone":{
"Number":"Phone number",
"Extension":"Extension number"
}
},
"PaymentInformation":{
"Payer":{
"Name":"Payer Name",
"Address":{
"AddressLine":"AddressLine",
"City":"City",
"StateProvinceCode":"StateProvinceCode",
"PostalCode":"PostalCode",
"CountryCode":"CountryCode"
},
"ShipperNumber":"Payer\u0027s shipper Number",
"AccountType":"AccountType",
"AttentionName":"AttentionName",
"Phone":{
"Number":"Phone number",
"Extension":"Extension number"
},
"EMailAddress":"EMailAddress"
},
"ShipmentBillingOption":{
"Code":"ShipmentBillingOption"
}
},
"Service":{
"Code":"Service code"
},
"HandlingUnitOne":{
"Quantity":"HandlingUnitOne quantity",
"Type":{
"Code":"HandlingUnitOne code"
}
},
"Commodity":{
"Description":"Commodity description",
"Weight":{
"UnitOfMeasurement":{
"Code":"UnitOfMeasurement code"
},
"Value":"Weight"
},
"NumberOfPieces":"NumberOfPieces",
"PackagingType":{
"Code":"PackagingType code"
},
"FreightClass":"FreightClass"
},
"ShipmentServiceOption":{
"WeekendPickupIndicator":""
},
"DensityEligibleIndicator":"",
"AdjustedWeightIndicator":"",
"HandlingUnitWeight":{
"Value":"HandlingUnitWeight",
"UnitOfMeasurement":{
"Code":"UnitOfMeasurement code"
}
},
"AlternateRateOptions":{
"Code":"AlternateRateOptions code"
},
"PickupRequest":{
"PickupDate":"PickupDate"
},
"TimeInTransitIndicator":"",
"GFPOptions":{
"OnCallInformation":{
"OnCallPickupIndicator":""
}
}
}
}