jlevers / selling-partner-api

A PHP client library for Amazon's Selling Partner API
BSD 3-Clause "New" or "Revised" License
404 stars 198 forks source link

Exception when calling ReportsV20210630Api->createReport: [400] { "errors": [ { "code": "InvalidInput", "message": "One or more required parameters missing", "details": "marketplaceIds;reportType;" } ] } #553

Closed SoporteBluco closed 1 year ago

SoporteBluco commented 1 year ago

Hello,

I'm executing this code:

require_once(__DIR__ . '/vendor/autoload.php');

use SellingPartnerApi\Api\ReportsApi;
use SellingPartnerApi\Api\SellersApi;
use SellingPartnerApi\Configuration;
use SellingPartnerApi\Endpoint;
use Dotenv\Dotenv;

$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load(__DIR__.'/.env');

$config = new Configuration();

$apiInstance = new ReportsApi($config);

$marketplaceIds = ['A1RKKUPIHCS9HS', 'A13V1IB3VIYZZH']; 

$reportType = 'GET_FLAT_FILE_OPEN_LISTINGS_DATA'; 

$reportOptions = ['marketplaceIds' => implode(',', $marketplaceIds)]; 

$apiInstance = new SellingPartnerApi\Api\ReportsV20210630Api($config);
$body = new \SellingPartnerApi\Model\ReportsV20210630\CreateReportSpecification(); // \SellingPartnerApi\Model\ReportsV20210630\CreateReportSpecification

try {
    $result = $apiInstance->createReport($body);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling ReportsV20210630Api->createReport: ', $e->getMessage(), PHP_EOL;
}

and I receive this error:

Exception when calling ReportsV20210630Api->createReport: [400] { "errors": [ { "code": "InvalidInput", "message": "One or more required parameters missing", "details": "marketplaceIds;reportType;" } ] }

My php version is: 8.0.25

I'm sure the data in .env is correct. I've tried a print_r($config) and I receive an array with all the Keys (LWA_CLIENT_ID, ....).

Thank you very much

jlevers commented 1 year ago

Try this:

use SellingPartnerApi\Api\ReportsV20210630Api as ReportsApi;
use SellingPartnerApi\Model\ReportsV20210630 as Reports;
// ...

$apiInstance = new ReportsApi($config);
$spec = new Reports\CreateReportSpecification([
    'report_type' => 'GET_FLAT_FILE_OPEN_LISTINGS_DATA',
    'data_start_time' => '2023-06-01T00:00:00Z',
    'data_end_time' => '2023-06-01T23:59:59Z',
    'marketplace_ids' => implode(',', $marketplaceIds),
]);

try {
    $result = $apiInstance->createReport($body);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling ReportsV20210630Api->createReport: ', $e->getMessage(), PHP_EOL;
}
AntoWkill commented 1 year ago

Hello i have the same issue.

$apiInstance = new SellingPartnerApi\Api\ReportsV20210630Api($config);
$body = new \SellingPartnerApi\Model\ReportsV20210630\CreateReportSpecification(['reportType' => 'GET_FLAT_FILE_ACTIONABLE_ORDER_DATA_SHIPPING', 'marketplaceIds' => 'APJ6JRA9NG5V4']); 

try {
    $result = $apiInstance->createReport($body);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling ReportsV20210630Api->createReport: ', $e->getMessage(), PHP_EOL;
}

Error: Exception when calling ReportsV20210630Api->createReport: [400] { "errors": [ { "code": "InvalidInput", "message": "One or more required parameters missing", "details": "marketplaceIds;reportType;" } ] }

AntoWkill commented 1 year ago

Solved with this code:

$marketplaceIds = array('APJ6JRA9NG5V4','A1RKKUPIHCS9HS','A1F83G8C2ARO7P','A13V1IB3VIYZZH','AMEN7PMS3EDWL','A1805IZSGTT6HS','A1PA6795UKMFR9','A2NODRKZP88ZB9','A1C3SOZRARQ6R3'); // string[] | A list of MarketplaceId values. Used to select orders that were placed in the specified marketplaces. See the [Selling Partner API Developer Guide](https://developer-docs.amazon.com/sp-api/docs/marketplace-ids) for a complete list of marketplaceId values.
$reportType = 'GET_FLAT_FILE_ACTIONABLE_ORDER_DATA_SHIPPING'; 

$body = new \SellingPartnerApi\Model\ReportsV20210630\CreateReportSpecification([
    'marketplace_ids' => $marketplaceIds,
    'report_type' => 'GET_FLAT_FILE_ACTIONABLE_ORDER_DATA_SHIPPING',
    'data_start_time' => '2023-06-01T00:00:00Z',
]);

$apiInstance = new SellingPartnerApi\Api\ReportsV20210630Api($config);
//$body = new \SellingPartnerApi\Model\ReportsV20210630\CreateReportSpecification(); // \SellingPartnerApi\Model\ReportsV20210630\CreateReportSpecification

try {
    $result = $apiInstance->createReport($body);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling ReportsV20210630Api->createReport: ', $e->getMessage(), PHP_EOL;
}