简体   繁体   中英

I can't show my inventory on my reports in Amazon Selling Partner API

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?

my expectation was that在此处输入图片说明

I solved my problem.

Firstly, If you want to see second image (my expectation) you have to need the document id.

So

  1. Create a report and get a report ID
  2. Get a documentID with using a reportID
  3. Use getReportDocument function with using documentID
  4. Open decrypto document and read file

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;
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM