Anonymous
UPS -Rate -API fehlt oder ungültiges Feld
Post
by Anonymous » 05 Mar 2025, 08:11
Ich versuche, UPS -Rate -API für eine meiner Apps einzurichten. Meine Daten sehen aus wie:
Code: Select all
{
"RateRequest": {
"Request": {
"RequestOption": "Rate"
},
"CustomerClassification": {
"Code": "00"
},
"Shipment": {
"Shipper": {
"Name": "**********",
"ShipperNumber": "*****",
"Address": {
"AddressLine": "7550 N Croname RD STE 500",
"City": "Niles",
"StateProvinceCode": "IL",
"PostalCode": "*****",
"CountryCode": "US"
}
},
"ShipTo": {
"Address": {
"PostalCode": "90001",
"CountryCode": "US"
}
},
"ShipFrom": {
"Address": {
"AddressLine": "******",
"City": "Los Angeles",
"StateProvinceCode": "*****",
"PostalCode": "*****",
"CountryCode": "US"
}
},
"Service": {
"Code": "03"
},
"TaxInformationIndicator": "True",
"NumOfPieces": "1",
"Package": [
{
"PackagingType": {
"Code": "02"
},
"PackageWeight": {
"Weight": "7.31",
"UnitOfMeasurement": {
"Code": "LBS"
}
}
}
],
"ShipmentRatingOptions": {
"NegotiatedRatesIndicator": "True"
}
}
}
}
Ich ziele auf die URL
https://onlinetools.ups.com/api/rating/v2409/rate , aber ich erhalte eine Antwort. Option. "}]}}
Während die Anforderung in der Nutzlast verfügbar ist. Was mache ich falsch? (Ich habe Zugriffstoken). < /P>
Mein Code für Anruf ist < /p>
Code: Select all
$version = "v2409";
$requestoption = "Rate";
$accessToken = $this->getUpsAccessToken(); // Get OAuth token
if (!$accessToken) {
return ['error' => 'Failed to get access token'];
}
$query = array();
$curl = curl_init();
$payload = $this->processPackageRateRequest($ShippingConstants, $PostalCode, $CountryCode, $BoxCount, $ShippingWeight, $ServiceType, $addressType);
//print_r(json_encode($payload));
curl_setopt_array($curl, [
CURLOPT_HTTPHEADER => [
"Authorization: Bearer $accessToken",
"Content-Type: application/json",
"transId: string",
"transactionSrc: testing",
"Accept: application/json",
],
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_URL => "https://onlinetools.ups.com/api/rating/" . $version . "/" . $requestoption . "?" . http_build_query($query),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$error = curl_error($curl);
curl_close($curl);
if ($error) {
echo "cURL Error #:" . $error;
} else {
echo $response;
}
Die Funktion "ProcessPackagerATeRequest" gibt die Nutzlast in formatierter Version zurück.
1741158699
Anonymous
Ich versuche, UPS -Rate -API für eine meiner Apps einzurichten. Meine Daten sehen aus wie: [code]{ "RateRequest": { "Request": { "RequestOption": "Rate" }, "CustomerClassification": { "Code": "00" }, "Shipment": { "Shipper": { "Name": "**********", "ShipperNumber": "*****", "Address": { "AddressLine": "7550 N Croname RD STE 500", "City": "Niles", "StateProvinceCode": "IL", "PostalCode": "*****", "CountryCode": "US" } }, "ShipTo": { "Address": { "PostalCode": "90001", "CountryCode": "US" } }, "ShipFrom": { "Address": { "AddressLine": "******", "City": "Los Angeles", "StateProvinceCode": "*****", "PostalCode": "*****", "CountryCode": "US" } }, "Service": { "Code": "03" }, "TaxInformationIndicator": "True", "NumOfPieces": "1", "Package": [ { "PackagingType": { "Code": "02" }, "PackageWeight": { "Weight": "7.31", "UnitOfMeasurement": { "Code": "LBS" } } } ], "ShipmentRatingOptions": { "NegotiatedRatesIndicator": "True" } } } } [/code] Ich ziele auf die URL https://onlinetools.ups.com/api/rating/v2409/rate, aber ich erhalte eine Antwort. Option. "}]}} Während die Anforderung in der Nutzlast verfügbar ist. Was mache ich falsch? (Ich habe Zugriffstoken). < /P> Mein Code für Anruf ist < /p> [code] $version = "v2409"; $requestoption = "Rate"; $accessToken = $this->getUpsAccessToken(); // Get OAuth token if (!$accessToken) { return ['error' => 'Failed to get access token']; } $query = array(); $curl = curl_init(); $payload = $this->processPackageRateRequest($ShippingConstants, $PostalCode, $CountryCode, $BoxCount, $ShippingWeight, $ServiceType, $addressType); //print_r(json_encode($payload)); curl_setopt_array($curl, [ CURLOPT_HTTPHEADER => [ "Authorization: Bearer $accessToken", "Content-Type: application/json", "transId: string", "transactionSrc: testing", "Accept: application/json", ], CURLOPT_POSTFIELDS => json_encode($payload), CURLOPT_URL => "https://onlinetools.ups.com/api/rating/" . $version . "/" . $requestoption . "?" . http_build_query($query), CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => "POST", ]); $response = curl_exec($curl); $error = curl_error($curl); curl_close($curl); if ($error) { echo "cURL Error #:" . $error; } else { echo $response; } [/code] Die Funktion "ProcessPackagerATeRequest" gibt die Nutzlast in formatierter Version zurück.