我已与Brink的运输API集成在一起。因此,当我每次尝试运行代码时,都会收到关于400(错误请求)的警告。
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: 无法识别的字段“ billingType”(类 com.bgs.restservice.vo.ShipmentRequest),未标记为可忽略(2 已知属性:[来源:“ requestId”,“ shipInfo”]) java.io.ByteArrayInputStream@51c5bd2e;行:1,列:42](通过 参考链: com.bgs.restservice.vo.ShipmentRequest [“ billingType”])
我将尝试使用ajax和python,但是两者都会产生相同的问题。我不知道有关的问题。这是我的python脚本
url = "https://bgstest.brinksglobal.com/BGSRestServices/rest/ship/createShipment"
header = {'Content-Type': 'application/json', 'Authorization': 'Bearer PGHNeooyREuo0+DqDe50tQ'}
list_data = {"requestId": "1246492019",
"billingType": "P",
"shipper": {"name": "BRIAN GAVIN",
"address1": "7322 SW FREEWAY SUITE 1810",
"address2": "SUITE 2400",
"city": "HOUSTON",
"provinceCode": "TX",
"postalCode": "77074",
"countryCode": "US",
"phoneNumber": "469.549.6618"},
"pickupLocation": {"name": "BRIAN GAVIN",
"address1": "7322 SW FREEWAY SUITE 1810",
"address2": "SUITE 2400",
"city": "HOUSTON",
"provinceCode": "TX",
"postalCode": "77074",
"countryCode": "US",
"phoneNumber": "469.549.6618"
},
"deliveryLocation": {"name": "AaronLuu",
"address1": "710 Dado St",
"address2": "",
"city": "San Jose",
"provinceCode": "CA",
"postalCode": "95131",
"countryCode": "US",
"phoneNumber": "469.549.6618"
},
"serviceType": "BP",
"modeOfTransportCode": "A",
"requestLabelImage": "true",
"shipmentLabelRequest": {"labelType": "PDF",
"printOption": "Label"
},
"shipmentItems": [{"insuranceLiabilityValue": "1.0",
"packageWeightUOM": "LBS",
"packageWeight": "1.0",
"netWeight": "1.0",
"netWeightUOM": "LBS",
"commodityId": "5",
"packageTypeCode": "PCP",
"termCode": "CIF"}]
}
response_decoded_json = requests.post(url, data=json.dumps(list_data), headers=header)
print(response_decoded_json.status_code)
print(response_decoded_json.text)
在这里,我尝试使用Ajax。
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>
<script type="text/javascript">
function brinks_post_req() {
jQuery.ajax({
cache: false,
crossDomain: true,
headers: {"Authorization": "Bearer PGHNeooyREuo0+DqDe50tQ"},
url:"https://bgstest.brinksglobal.com/BGSRestServices/rest/ship/createShipment",
type: "POST",
contentType: "application/json",
data:JSON.stringify({"requestId": "985743",
"billingType": "P",
"shipper": {
"name": "BRIAN GAVIN",
"address1": "7322 SW FREEWAY SUITE 1810",
"address2": "SUITE 2400",
"city": "HOUSTON",
"provinceCode": "TX",
"postalCode": "77074",
"countryCode": "US",
"phoneNumber": "469.549.6618"},
"consignee":{"name": "AaronLuu",
"address1": "710 Dado St",
"address2": "",
"city": "San Jose",
"provinceCode": "CA",
"postalCode": "95131",
"countryCode": "US",
"phoneNumber": "469.549.6618"},
"pickupLocation": {
"name": "BRIAN GAVIN",
"address1": "7322 SW FREEWAY SUITE 1810",
"address2": "SUITE 2400",
"city": "HOUSTON",
"provinceCode": "TX",
"postalCode": "77074",
"countryCode": "US",
"phoneNumber": "469.549.6618" },
"deliveryLocation": {"name": "AaronLuu",
"address1": "710 Dado St",
"address2": "",
"city": "San Jose",
"provinceCode": "CA",
"postalCode": "95131",
"countryCode": "US",
"phoneNumber": "469.549.6618"},
"serviceType": "DD",
"modeOfTransportCode": "A",
"requestLabelImage": "true",
"shipmentLabelRequest": { "labelType": "PDF","printOption": "Label"},
"shipmentItems": [{"insuranceLiabilityValue": "1.0", "packageWeightUOM": "LBS",
"packageWeight": "1.0","netWeight": "1.0",
"netWeightUOM": "LBS", "commodityId": "5",
"packageTypeCode": "PCP","termCode": "CIF"}]
}),
dataType:"json",
success: function( jsonObj, textStatus, xhr ) {
var htmlContent = jQuery( "#logMsgDiv" ).html( ) + "<p>Create Shipment " +" --- jsonResponse : " + JSON.stringify(jsonObj) + "</p>";
jQuery( "#logMsgDiv" ).html( htmlContent );
},
error: function( xhr, textStatus, errorThrown ) {console.log( "HTTP Status: " + xhr.status );
console.log( "HTTP Response Text: " +xhr.responseText );
console.log( "Error textStatus: " + textStatus );
console.log( "Error thrown: " + errorThrown );}
});
}
brinks_post_req();
</script>