selling-partner-api icon indicating copy to clipboard operation
selling-partner-api copied to clipboard

ShippingV2Api::getRates Getting 400-InvalidInput response with no information about error

Open shanijahania opened this issue 1 year ago • 1 comments

Problem description:

I am trying to send getRates() request on ShippingApiV2 to get the rates list. I have passed all the required parameters and and checked the values many times. but still getting the same error.

Error:

[400] {
      "errors": [
        {
          "code": "InvalidInput",
          "message": "Invalid input",
          "details": "Provided input is invalid. Please verify."
        }
      ]
    }

Code

$body = new GetRatesRequest(); // \SellingPartnerApi\Model\ShippingV2\GetRatesRequest
$body->setShipDate('2023-07-13T19:15:40Z');

// Set Channel Details
$orderDetails = new AmazonOrderDetails(['order_id' => '114-1234567-1234567']);
$channelDetails = new ChannelDetails(['channel_type' => 'AMAZON', 'amazon_order_details' => $orderDetails]);

$body->setChannelDetails($channelDetails);

// Set Ship from address
$shipFromAddress = new Address();
$shipFromAddress->setName('John Doe');
$shipFromAddress->setAddressLine1('test street address 1');
$shipFromAddress->setStateOrRegion('IL');
$shipFromAddress->setCity('Belleville');
$shipFromAddress->setCountryCode('US');
$shipFromAddress->setPostalCode('12345');
$shipFromAddress->setPhoneNumber('1234567890');

$body->setShipFrom($shipFromAddress);

// Set Packages
$package = new Package();

// Set Dimensions
$dimension = new Dimensions(['length' => '2', 'width' => '2','height' => '2','unit' => 'INCH']);
$package->setDimensions($dimension);

// Set package weight
$weight = new Weight(['unit' => 'POUND', 'value' => '1']);
$package->setWeight($weight);

// Set Package Insured Value
$insuredValue = new Currency(['unit' => 'USD', 'value' => '10']);
$package->setInsuredValue($insuredValue);

$packageItems = [];

$packageItem = new Item();
$packageItem->setQuantity('1');

$itemValue = new Currency(['unit' => 'USD', 'value' => '1.25']);
$packageItem->setItemValue($itemValue);

$itemWeight = new Weight(['value' => 'POUND', 'unit' => '1']);
$packageItem->setWeight($itemWeight);

$packageItems[] = $packageItem;

$package->setItems($packageItems);
$package->setPackageClientReferenceId('adsfasdfs');
$packages = [$package];
$body->setPackages($packages);
$x_amzn_shipping_business_id = 'AmazonShipping_US';
$response = $apiInstance->getRates($body, $x_amzn_shipping_business_id);

shanijahania avatar Jul 12 '23 12:07 shanijahania

I've just faced the same problem here and found the solution so hopefully this can be avoided in future. 'unit' values must be integers/floats and not string as in the above, then you should get a more constructive error back. Also value and unit are incorrect on $itemWeights in the asbove code.

jmwill86 avatar May 28 '24 17:05 jmwill86