Reputation: 631
object(ClouSale\AmazonSellingPartnerAPI\Models\Reports\GetReportResponse)#482 (1) { ["container":protected]=> array(2) { ["payload"]=> object(ClouSale\AmazonSellingPartnerAPI\Models\Reports\Report)#491 (1) { ["container":protected]=> array(11) { ["marketplace_ids"]=> array(1) { [0]=> string(14) "A1VC38T7YXB528" } ["report_id"]=> string(11) "55933018913" ["report_type"]=> string(30) "GET_MERCHANT_LISTINGS_ALL_DATA" ["data_start_time"]=> object(DateTime)#506 (3) { ["date"]=> string(26) "2021-10-13 04:42:10.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } ["data_end_time"]=> object(DateTime)#483 (3) { ["date"]=> string(26) "2021-10-13 04:42:10.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } ["report_schedule_id"]=> NULL ["created_time"]=> object(DateTime)#502 (3) { ["date"]=> string(26) "2021-10-13 04:42:10.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } ["processing_status"]=> string(4) "DONE" ["processing_start_time"]=> object(DateTime)#481 (3) { ["date"]=> string(26) "2021-10-13 04:42:16.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } ["processing_end_time"]=> object(DateTime)#480 (3) { ["date"]=> string(26) "2021-10-13 04:42:25.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } ["report_document_id"]=> string(73) "amzn1.spdoc.1.3.2149a182-4354-4177-b03e-0bc4552cb190.T25GAW47NVJ50Z.47700" } } ["errors"]=> NULL } }
I want to show my inventory using Amazon Selling Partner API. Firstly, I created a report for this. I have report id, document id etc. When I pull the report with using GetReports function using this information, the inventory does not appear. Is it normal?
Upvotes: 0
Views: 704
Reputation: 631
I solved my problem.
Firstly, If you want to see second image (my expectation) you have to need the document id.
So
This is my code (on laravel)
public function getInventoryReportData() {
header('Content-Type: text/html; charset=utf-8');
$options = [
'refresh_token' => self::constOptions["amazon"]["refresh_token"],
'client_id' => self::constOptions["amazon"]["client_id"],
'client_secret' => self::constOptions["amazon"]["client_secret"],
'region' => \ClouSale\AmazonSellingPartnerAPI\SellingPartnerRegion::$FAR_EAST,
'access_key' => self::constOptions["amazon"]["access_key"],
'secret_key' => self::constOptions["amazon"]["secret_key"],
'endpoint' => \ClouSale\AmazonSellingPartnerAPI\SellingPartnerEndpoint::$FAR_EAST,
'role_arn' => self::constOptions["amazon"]["role_arn"],
];
$accessToken = \ClouSale\AmazonSellingPartnerAPI\SellingPartnerOAuth::getAccessTokenFromRefreshToken(
$options['refresh_token'],
$options['client_id'],
$options['client_secret']
);
$config = \ClouSale\AmazonSellingPartnerAPI\Configuration::getDefaultConfiguration();
$config->setHost($options['endpoint']);
$config->setAccessToken($accessToken);
$config->setAccessKey($options['access_key']);
$config->setSecretKey($options['secret_key']);
$config->setRegion($options['region']);
$apiInstance = new \ClouSale\AmazonSellingPartnerAPI\Api\ReportsApi($config);
$report_document_id = "YOUR_DOCUMENT_ID_IN_HERE";
try {
$result = $apiInstance->getReportDocument($report_document_id);
$key = base64_decode($result->getPayload()->getEncryptionDetails()->getKey());
$iv = base64_decode($result->getPayload()->getEncryptionDetails()->getInitializationVector());
$decryptedData = openssl_decrypt(file_get_contents($result->getPayload()->getUrl()), 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);
$convertEncodeData = mb_convert_encoding($decryptedData, 'UTF-8', 'ASCII, JIS, UTF-8, SJIS');
echo $convertEncodeData;
} catch (Exception $e) {
echo 'Exception when calling ReportsApi->getReportDocument: ', $e->getMessage(), PHP_EOL;
}
}
Upvotes: 0