jlevers / selling-partner-api

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

getReportDocument - unsupported Document ID #448

Closed greenhof closed 1 year ago

greenhof commented 1 year ago

Problem description:

I have all the PII roles in my account and i have generated the report GET_FLAT_FILE_VAT_INVOICE_DATA_REPORT. The report processing is ended with status DONE. I get the report document id (which starts with amzn1.spdoc). But i can not get the document using getReportDocument. Here is the error message i receive when i do so:

Exception when calling ReportsApi->getReport: [400] {
  "errors": [
    {
      "code": "InvalidInput",
      "message": "Invalid or unsupported document ID found",
      "details": ""
    }
  ]
}

And here is the part of the code which generates this error:

$config = new SellingPartnerApi\Configuration([
    "lwaClientId" => "amzn1.*******************",
    "lwaClientSecret" => "1***********************",
    "lwaAccessToken" =>$access_token,
    "lwaRefreshToken" => $refresh_token,
    "awsAccessKeyId" => "A**************",
    "awsSecretAccessKey" => "8*****************",
    "endpoint" => SellingPartnerApi\Endpoint::EU,  // or another endpoint from lib/Endpoint.php
    "roleArn" => "arn:***********************",
  ]);

$reportsApi = new ReportsApi($config);

$documentId = 'amzn1.spdoc.****************';
$reportType = ReportType::GET_FLAT_FILE_VAT_INVOICE_DATA_REPORT;
try {
    $reportDocumentInfo = $reportsApi->getReportDocument($documentId, $reportType['name']);
    print_r($reportDocumentInfo);

    $docToDownload = new SellingPartnerApi\Document($reportDocumentInfo, $reportType);
    $contents = $docToDownload->download(false);  // The raw report text
    //$data = $docToDownload->getData();
    //echo count($data);
    //echo $contents;
    $file =  "./reports/". $kdnr ."-" . $report_id . "-" . $reportType['name'] . "-". time(). ".tsv";
    file_put_contents($file, $contents);
}  catch (Exception $e) {
    echo 'Exception when calling ReportsApi->getReport: ', $e->getMessage(), PHP_EOL;
}
greenhof commented 1 year ago

GET_FLAT_FILE_VAT_INVOICE_DATA_REPORT seems to be not restricted, upon setting restricted to false in reportTypes for this report, i was able to download it without any issues.

Julian3004 commented 1 year ago

What exactly do you mean with set restricted to false? U mean in the ReportOptions?

greenhof commented 1 year ago

What exactly do you mean with set restricted to false? U mean in the ReportOptions?

in the file ReportType.php set restricted to false for the report GET_FLAT_FILE_VAT_INVOICE_DATA_REPORT

jlevers commented 1 year ago

I think I missed this issue because it got closed relatively quickly. According to Amazon's documentation, that report is restricted (you supposedly need the Tax Invoicing role). Are you getting PII in that report when you request it as a non-restricted report?

greenhof commented 1 year ago

I think I missed this issue because it got closed relatively quickly. According to Amazon's documentation, that report is restricted (you supposedly need the Tax Invoicing role). Are you getting PII in that report when you request it as a non-restricted report?

i manage to get this report only when i request it as a non-restricted report. And yes i get PII data in it.

jlevers commented 1 year ago

Interesting, and do you have access to PII in general, via one of the restricted SP API roles?

greenhof commented 1 year ago

Interesting, and do you have access to PII in general, via one of the restricted SP API roles?

yes, we have all the restricted roles and, we generate and download reports containing PII for multiple sellers using our App. Only with this report we have this issue.