When I am calling selling partner Amazon fba inbound shipment getShipments() api i am getting a NextToken.
But when again calling the API with NextToken it gives me below error even though NextToken exist -
[400]
{ "errors": [ { "code": "InvalidInput", "message": "Request is invalid - NextToken must not be empty", "details": "" } ] }
Below is my code:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// See README for more information on the Configuration object's options
$config = new SellingPartnerApi\Configuration([
"lwaClientId" => "<LWA client ID>",
"lwaClientSecret" => "<LWA client secret>",
"lwaRefreshToken" => "<LWA refresh token>",
"awsAccessKeyId" => "<AWS access key ID>",
"awsSecretAccessKey" => "<AWS secret access key>",
"endpoint" => SellingPartnerApi\Endpoint::NA // or another endpoint from lib/Endpoints.php
]);
$api = new SellingPartnerApi\Api\FbaInboundV0Api($config);
// Input data
$mpId = $_POST['txtMarketplaceId']; // Blocked since not required
$shpStatus = $_POST['txtShpStatus'];
try {
$shipments = $api->getShipments('SHIPMENT', [$mpId], [$shpStatus]);
if(!empty($shipments['payload']['shipment_data'])) {
// Check if it has next token
if(isset($shipments['payload']['next_token'])){
// Get next token
$nextToken = $shipments['payload']['next_token'];
// HERE I AM GETTING ERROR
$resNextToken = $api->getShipments('NEXT_TOKEN', ['NextToken' => $resNextToken]);
print_r($resNextToken); die;
}
} else {
echo "No shipments found";
}
} catch (Exception $e) {
echo "Exception when calling get shipments API '.$e->getMessage()";
}
?>
Am I making getShipments() request with NextToken incorrectly?
I solved this using
$api->getShipments('NEXT_TOKEN', [$mpId], null, null, null, null, $nextToken);
Look the order of params in getShipments() method in API code
/**
* Operation getShipments
*
* @param string $query_type Indicates whether shipments are returned using shipment information (by providing the ShipmentStatusList or ShipmentIdList parameters), using a date range (by providing the LastUpdatedAfter and LastUpdatedBefore parameters), or by using NextToken to continue returning items specified in a previous request. (required)
* @param string $marketplace_id A marketplace identifier. Specifies the marketplace where the product would be stored. (required)
* @param string[] $shipment_status_list A list of ShipmentStatus values. Used to select shipments with a current status that matches the status values that you specify. (optional)
* @param string[] $shipment_id_list A list of shipment IDs used to select the shipments that you want. If both ShipmentStatusList and ShipmentIdList are specified, only shipments that match both parameters are returned. (optional)
* @param string $last_updated_after A date used for selecting inbound shipments that were last updated after (or at) a specified time. The selection includes updates made by Amazon and by the seller. (optional)
* @param string $last_updated_before A date used for selecting inbound shipments that were last updated before (or at) a specified time. The selection includes updates made by Amazon and by the seller. (optional)
* @param string $next_token A string token returned in the response to your previous request. (optional)
*
* @throws \SellingPartnerApi\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return \SellingPartnerApi\Model\FbaInboundV0\GetShipmentsResponse
*/
public function getShipments($query_type, $marketplace_id, $shipment_status_list = null, $shipment_id_list = null, $last_updated_after = null, $last_updated_before = null, $next_token = null)
{
$response = $this->getShipmentsWithHttpInfo($query_type, $marketplace_id, $shipment_status_list, $shipment_id_list, $last_updated_after, $last_updated_before, $next_token);
return $response;
}