I am trying to confirm Amazon's orders using confirmShipment() from from jlevers/selling-partner-api as described in the GitHub below but I am getting Fatal error: Uncaught Error: Class 'null' not found /vendor/jlevers/selling-partner-api/lib/ObjectSerializer.php:366
https://github.com/jlevers/selling-partner-api/
I successfully create the $apiInstance and the $payload, but when I execute it I get this error from the ObjectSerializer:
Fatal error: Uncaught Error: Class 'null' not found in /vendor/jlevers/selling-partner-api/lib/ObjectSerializer.php:366 Stack trace: #0 /vendor/jlevers/selling-partner-api/lib/Api/OrdersV0Api.php(92):
SellingPartnerApi\ObjectSerializer::deserialize(Object(stdClass), 'null', Array) #1 /vendor/jlevers/selling-partner-api/lib/Api/OrdersV0Api.php(55):
SellingPartnerApi\Api\OrdersV0Api->confirmShipmentWithHttpInfo('114-0297756-279...', Object(SellingPartnerApi\Model\OrdersV0\ConfirmShipmentRequest)) #2 /amazon_settings.php(457):
SellingPartnerApi\Api\OrdersV0Api->confirmShipment('114-0297756-279...', Object(SellingPartnerApi\Model\OrdersV0\ConfirmShipmentRequest)) #3 /scripts/test.php(65):
Amazon->fn_confirmShipment('/home/scripts...') #4 {main} thrown in /vendor/jlevers/selling-partner-api/lib/ObjectSerializer.php on line 366
This is what I am using:
$apiInstance = new SellingPartnerApi\Api\OrdersV0Api($config);
$order_id = 'order_id_example'; // string | An Amazon-defined order identifier, in 3-7-7 format (correct order number being passed).
$payload = new \SellingPartnerApi\Model\OrdersV0\ConfirmShipmentRequest(); // \SellingPartnerApi\Model\OrdersV0\ConfirmShipmentRequest | Request body of confirmShipment.
try {
$apiInstance->confirmShipment($order_id, $payload);
} catch (Exception $e) {
echo 'Exception when calling OrdersV0Api->confirmShipment: ', $e->getMessage(), PHP_EOL;
}
This is the $payload that ConfirmShipmentRequest generates:
SellingPartnerApi\Model\OrdersV0\ConfirmShipmentRequest Object
(
[container:protected] => Array
(
[package_detail] => Array
(
[package_reference_id] => 2790602
[carrier_code] => FedEx
[shipping_method] => Ground
[tracking_number] => 63828440XXX
[ship_date] => 2023-11-07T07:17:07-00:00
[order_items] => Array
(
[order_item_id] => 87699213804801
[quantity] => 4
)
)
[cod_collection_method] =>
[marketplace_id] => ATVPDKIKX0DER
)
)
Am I passing the information in the payload incorrectly? The error says Class 'null' not found, but I am passing all the parameters inside $apiInstance->confirmShipment, any help is appreciated
I tried omitting the order_items, also passing them as a nested array
After updating to version 5.10.2 as suggested by Filip I was getting an
PackageReferenceIderror which later on was addressed by creating new protected containers first then adding the data instead of just passing arrays to them. The code below is a little more detailed than what is available in github: