amazon - 我无法在 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 } }
我想使用 Amazon Selling Partner API 显示我的库存。首先,我为此创建了一份报告。我有报告 ID、文档 ID 等。当我使用 GetReports 函数使用此信息提取报告时,不会出现库存。正常吗?
解决方案
我解决了我的问题。
首先,如果您想查看第二张图片(我的期望),您必须需要文档 ID。
所以
- 创建报告并获取报告 ID
- 使用 reportID 获取 documentID
- 使用 getReportDocument 函数和 documentID
- 打开解密文档并读取文件
这是我的代码(在 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;
}
}
推荐阅读
- python - 断言两个 sklearn 对象相等
- java - Spring Boot没有拾取属性
- html - Angular 5 - HTTP拦截器拦截401作为状态码0
- fast-ai - fast-ai 2 中的等效 api
- ios - 将 UIGestureRecognizer 添加到自定义 .xib 视图
- c++ - 推力:就位一个成员的exclusive_scan
- reactjs - 来自 React Axios 帖子的 MongoDB 数据库中的数组保存为空白
- amazon-web-services - 如何从 dynamodb 中删除项目
- reactjs - React - 动态导入pdf文件的路径
- django - 无法找到包裹达芙妮