amazon
“我正在尝试使用 NPM 包‘amazon-sp-api’从 AWS 卖家合作伙伴 API 下载报告,但我得到的响应是这种数据格式:
[{
���R�K�/��Y�_Z��\x06�6*��r9,'\x04SBp�S<B�[ۚZ["��)w<�\x03�J�
: '��-����HN \x0BX\x00����w��L��,��\x0FV����\x19\x15��]����2<�c�Xc�����\r�\x0F\r@h�.�\x0F�������3�z�'
},{...},...]
这是我的代码:
const SellingPartnerAPI = require('amazon-sp-api');
require('dotenv').config({ path: `${__dirname}/./../.env` });
const path = require('path');
async function main() {
try {
let sellingPartner = new SellingPartnerAPI({
region: process.env.REGION,
refresh_token: process.env.REFRESH_TOKEN,
credentials: {
SELLING_PARTNER_APP_CLIENT_ID:
process.env.SELLING_PARTNER_APP_CLIENT_ID,
SELLING_PARTNER_APP_CLIENT_SECRET:
process.env.SELLING_PARTNER_APP_CLIENT_SECRET,
AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY,
AWS_SELLING_PARTNER_ROLE: process.env.AWS_SELLING_PARTNER_ROLE,
},
});
let res = await sellingPartner.callAPI({
operation: 'reports.getReports',
query: {
MarketplaceIds: 'A2ZV50J4W1RKNI',
reportTypes: 'GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE',
},
version: '2021-06-30',
});
if (res[0].processingStatus === 'DONE') {
let report_document = await sellingPartner.callAPI({
operation: 'reports.getReportDocument',
path: {
reportDocumentId: res[0].reportDocumentId,
},
});
let report = await sellingPartner.download(
{ reportDocumentId: res[0].reportDocumentId, url: report_document.url },
{
//charset:'cp1252'
json: true,
file: path.join(
__dirname,
'..',
'files',
`${res[0].reportType}.json`
),
}
);
console.log('report', report);
} else {
console.log(res[0].processingStatus);
}
} catch (e) {
console.log(e);
}
}
main();
我一直在对“字符集”参数进行更改,但它们没有用。我还应该审查或更改什么?预先感谢您的帮助!
回答如下:
amazon
“我正在尝试使用 NPM 包‘amazon-sp-api’从 AWS 卖家合作伙伴 API 下载报告,但我得到的响应是这种数据格式:
[{
���R�K�/��Y�_Z��\x06�6*��r9,'\x04SBp�S<B�[ۚZ["��)w<�\x03�J�
: '��-����HN \x0BX\x00����w��L��,��\x0FV����\x19\x15��]����2<�c�Xc�����\r�\x0F\r@h�.�\x0F�������3�z�'
},{...},...]
这是我的代码:
const SellingPartnerAPI = require('amazon-sp-api');
require('dotenv').config({ path: `${__dirname}/./../.env` });
const path = require('path');
async function main() {
try {
let sellingPartner = new SellingPartnerAPI({
region: process.env.REGION,
refresh_token: process.env.REFRESH_TOKEN,
credentials: {
SELLING_PARTNER_APP_CLIENT_ID:
process.env.SELLING_PARTNER_APP_CLIENT_ID,
SELLING_PARTNER_APP_CLIENT_SECRET:
process.env.SELLING_PARTNER_APP_CLIENT_SECRET,
AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY,
AWS_SELLING_PARTNER_ROLE: process.env.AWS_SELLING_PARTNER_ROLE,
},
});
let res = await sellingPartner.callAPI({
operation: 'reports.getReports',
query: {
MarketplaceIds: 'A2ZV50J4W1RKNI',
reportTypes: 'GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE',
},
version: '2021-06-30',
});
if (res[0].processingStatus === 'DONE') {
let report_document = await sellingPartner.callAPI({
operation: 'reports.getReportDocument',
path: {
reportDocumentId: res[0].reportDocumentId,
},
});
let report = await sellingPartner.download(
{ reportDocumentId: res[0].reportDocumentId, url: report_document.url },
{
//charset:'cp1252'
json: true,
file: path.join(
__dirname,
'..',
'files',
`${res[0].reportType}.json`
),
}
);
console.log('report', report);
} else {
console.log(res[0].processingStatus);
}
} catch (e) {
console.log(e);
}
}
main();
我一直在对“字符集”参数进行更改,但它们没有用。我还应该审查或更改什么?预先感谢您的帮助!
回答如下: