amzn / selling-partner-api-models

This repository contains OpenAPI models for developers to use when developing software to call Selling Partner APIs.
Apache License 2.0
612 stars 736 forks source link

Access to PII information with RDT token #4287

Open Awenega opened 1 week ago

Awenega commented 1 week ago

Hi, i'm tring to retrieve the VAT number ID of a client. I've the PII role for Tax Invoice for my application.

I'm making the call for RDT token with this object:

restrictedResource = {"method": "GET", "path": f"/orders/v0/orders/{order_id}", "dataElements": ["buyerTaxInformation"]}

But the response is:

{'errors': [{'code': 'InvalidInput', 'message': 'Application does not have access to one or more requested data elements: [buyerTaxInformation]', 'details': ''}]}

Why I can't get the RDT token if I've the Tax Invoice PII role enabled?

jawheral commented 1 week ago

Hi @Awenega,

The buyerTaxInformation is only available to the Turkey marketplace which is part of the EU region, did you make sure you are calling SP-API in the EU region?

Screenshot 2024-11-04 at 10 26 22

Best, Jawher Selling Partner Developer Services

Awenega commented 1 week ago

Hi,

Yes, i'm calling sp-api in the EU region, but i'm using the IT marketplace. Since Is avaiable only for the TR marketplace, what should i use in order to get the VAT Number of a buyer for the IT marketplace?

jawheral commented 1 week ago

Hi @Awenega,

First, to rule out any issues you might have with Tokens API, can you try requesting with "dataElements": ["buyerInfo"]?

Regarding getting the Buyer VAT number, for sellers who are neither enrolled in VCS nor in VCS Lite, you should rely on Orders report and FBA Shipments Invoicing report. These are: GET_ORDER_REPORT_DATA_INVOICING and GET_AMAZON_FULFILLED_SHIPMENTS_DATA_INVOICING. When not enrolled, the seller should activate the order reports columns that are required for invoicing. This can be done from the column picker on Seller Central: https://sellercentral.amazon.co.uk/order-reports-and-feeds/column-picker?source=/order-reports-and-feeds/reports/ref=xx_orderrpt_dnav_xxon. Billing, Buyer tax identifiers (incl. Buyer VAT Number) can be activated on the page.

If the seller is enrolled in VCS Lite, please make sure to use VIDR reports to get the VAT number and all other data points needed for invoicing. If the Seller is enrolled in VCS, where Amazon generates invoices automatically, please check the Amazon VAT Calculation Report.

Best, Jawher Selling Partner Developer Services

Awenega commented 1 week ago

Hi Jawher,

thank you for the detailed explaination.

I'm not enrolled in VCS nor in VCS Lite, and for this reason I want to automatize the invoice generation by myself.

I've tried the report types that you suggested, but everytime i got this response: {'errors': [{'code': 'Unauthorized', 'message': 'Access to the resource is forbidden', 'details': ''}]}

In particular, what I do is to request that type of report, than I retrive the reportDocumentId of the report and then, using an RDT token I get the document. I get the token using the following restrictedResource as object: restrictedResource = {"method": "GET", "path": f"/reports/2021-06-30/documents/{reportDocumentId}"}

But the problem seems to happen before I can get the RDT token. It happen when i request the report with that type of report_value that you suggested, using the standard access token. I've checked that i've the PII role enable of Tax invoicing, so I don't understand where is the problem...

jawheral commented 1 week ago

Hi @Awenega,

Your usage of the Tokens API looks good to me.

Did you self-authorize your app again after it received the Tax Invoicing role? If the authorization token you are currently using was created before the activation of the Tax Invoicing role, you need to re-authorize again.

If this doesn't work, I suggest that you contact Developer Support.

Best, Jawher Selling Partner Developer Services

Awenega commented 1 week ago

Hi Jawheral,

I self-authorize my app again and now seems that it works. So it creates the request to generate the report.

But, now, the problem is that everytime that i request this kind of report, checking the status it goes from IN_QUEUE to IN_PROGRESS to CANCELLED.

The body that I use for the request is the following:

body['dataStartTime'] = 2024-10-19T22:00:00+00:00 (isoformat)
body['dataEndTime'] = 2024-11-04T18:56:21.418472+00:00 (isoformat)
body['marketplaceIds'] = ['APJ6JRA9NG5V4', 'A1RKKUPIHCS9HS', 'A1PA6795UKMFR9']
body['reportType'] = "GET_ORDER_REPORT_DATA_INVOICING

I usually use this body with the report of all orders without the PII (and it works). I don't understand what's wrong with this request, since is it seems to be the same

jawheral commented 1 week ago

Hi @Awenega,

The GET_ORDER_REPORT_DATA_INVOICING can only be scheduled as per the documentation.

Screenshot 2024-11-05 at 09 54 00

Please follow this tutorial to learn more about scheduling and retrieving reports.

I hope this helps!

Best, Jawher Selling Partner Developer Services

Awenega commented 1 week ago

Hi Jawher,

thank you for the informations. Following the documentation, I'm scheduling this kind of report and I'm using AWS SQS in order to get the notification and check the processingStatus (using the Notification api i've created the subscription).

Unfortunately, I still not being able to correctly get the report. It always says CANCELLED:

{
  "notificationVersion" : "2020-09-04",
  "notificationType" : "REPORT_PROCESSING_FINISHED",
  "payloadVersion" : "1.0",
  "eventTime" : "2024-11-05T15:49:32.141Z",
  "payload" : {
    "reportProcessingFinishedNotification" : {
      "sellerId" : "***",
      "accountId" : "amzn1.merchant.o.***",
      "reportId" : "****",
      "reportType" : "GET_FLAT_FILE_ORDER_REPORT_DATA_INVOICING",
      "processingStatus" : "CANCELLED"
    }
  },
  "notificationMetadata" : {
    "applicationId" : "amzn1.sp.solution.****",
    "subscriptionId" : "****",
    "publishTime" : "2024-11-05T15:49:32.182Z",
    "notificationId" : "****"
  }
}

I also checked if I have other reports scheduled with the same report type, but it is not the case (i've cancelled all the scheduled report in order to have only this scheduled report)

The output of the getReportSchedule request to create the scheduled report is the following:

{'reportSchedules': [{
'reportType': 'GET_FLAT_FILE_ORDER_REPORT_DATA_INVOICING', 
'marketplaceIds': ['APJ6JRA9NG5V4'], 
'period': 'PT15M', 
'nextReportCreationTime': '2024-11-05T16:02:40+00:00', 
'reportScheduleId': '****'
}]} 

Also, from what I believe, there are two reasons why a report can result in CANCELLED status:

I exclude the first one. Instead, for the second one, should not be the case, since I've received many orders in the last days, so it should not be empty...

jawheral commented 1 week ago

Hi @Awenega,

I'm not able to tell what exactly could be causing the report to be Cancelled. We need more details to know the exact issue, please create a case with Developer Support providing all the necessary details such as the reportId, sellerId, marketplaceId,...

Feel free to share the support case number once you have it so we can track it.

Thank you for your understanding!

Best, Jawher Selling Partner Developer Services

Awenega commented 1 week ago

Hi Jawher,

The case number is 10486330002, thank you very much for your help!

Awenega commented 4 days ago

Hi @jawheral,

just an info about this problem. Is it possible to pass a start time and end time for a scheduled report as for a standard report?

I don't mean the period that specifies how often the report should be generated, but rather to a specific date range for which I want orders within the report.

Thank you

jawheral commented 4 days ago

Hi @Awenega,

Yes, you can provide the reportOptions for a scheduled report. This can be passed as part of CreateReportScheduleSpecification.

Best, Jawher Selling Partner Developer Services