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
580 stars 730 forks source link

UPLOAD_VAT_INVOICE #1158

Closed biancahuluban closed 1 year ago

biancahuluban commented 3 years ago

We need the documentation for UPLOAD_VAT_INVOICE because we need to automatically upload invoices via the Feed API. There is no clear statement if we can upload multiple invoices and credit notes on a specific order with multiple order items.

Here is the link to pdf documentation that states that this FeedType exists. https://m.media-amazon.com/images/G/03/B2B/invoice-uploader-developer-documentation.pdf

Thank you, if someone tested this FeedType please let us know how it goes.

fernlop commented 3 years ago

I'm using this Feed Type and a few weeks ago it was fixed and is now fully working. The process is as follows:

  1. Get URL and encryption details for upload using the createFeedDocument method. You must put "contentType": "application/pdf" in the body of the request.
  2. Encrypt the invoice using AES-CBC with the encryption key and IV received in first step
  3. Upload invoice to the URL received in the first step using a simple PUT request. You must put "Content-Type": "application/pdf" in the headers
  4. Create the feed using the "createFeed" method with the following body:
    {
    feedType: "UPLOAD_VAT_INVOICE",
    marketplaceIds: [MARKETPLACEID_OF_ORDER],
    inputFeedDocumentId: documentId, // received in first step
    feedOptions: {
        "metadata:invoicenumber": INVOICE_NUMBER,
        "metadata:orderid": AMAZON_ORDER_ID
        // optional!
        "metadata:totalamount": INVOICE_AMOUNT
        "metadata:totalvatamount": INVOICE_VAT_AMOUNT
    }
    }

    You will received the FeedID, which you ca use to track if everything worked. As this was not asked in this issue, I won't explain this but here is the code i used in NodeJS usning my own SDK:

const FeedStatus = await amzSDK.request({
    account,
        region: "eu",
        type: "getFeed",
        data: "50653018715",//feedRes[0].feedId,
        accessToken: mwsAccountConfig.accessToken,
        iamUserAuth: auth,
        bottleneckConfig: {
            ...auth.redisAuth
        }
})
console.log(FeedStatus)

const FeedDocument = await amzSDK.request({
    account,
        region: "eu",
        type: "getFeedDocument",
        data: FeedStatus[0].resultFeedDocumentId,
        accessToken: mwsAccountConfig.accessToken,
        iamUserAuth: auth,
        bottleneckConfig: {
            ...auth.redisAuth
        }
})
const FeedDocumentEncryption = {
    iv: Buffer.from(FeedDocument[0].encryptionDetails.initializationVector, 'base64'),
    key: Buffer.from(FeedDocument[0].encryptionDetails.key, 'base64'),
    url: FeedDocument[0].url
}
const FeedDocumentFile = await axios.get(FeedDocumentEncryption.url, {responseType: 'arraybuffer'}).then(r => Buffer.from(r.data, "binary"));
const decryptedFile = await aes.decrypt(FeedDocumentFile, FeedDocumentEncryption.key, {name: 'AES-CBC', iv: FeedDocumentEncryption.iv});
console.log(Utf8ArrayToStr(decryptedFile))
fernlop commented 3 years ago

And to your second question, this only works for one invoice, not multiple.

kissn01 commented 3 years ago

The first step [createFeedDocument() to create a feed document] The second step [encryptAndUpload_fromString() encrypts and uploads the feed data] I have set body.setContentType("application/pdf;charset=UTF-8"); But the interface still returns an error =================line================== Feed Processing Summary: Number of records processed 1 Number of records successful 0

original-record-number sku error-code error-type error-message 1 7xxx3 Error Invoice uploaded is not pdf for shipmentId N/A, orderId 026-xxxxxxx-6868357 and InvoiceNumber 09xxx52 null =================line==================

stefnats commented 3 years ago

@kissn01 there is a PR for a guide to uploading vat invoices made by @fernlop (great job!). i'll link the guide directly, so you can see it without having to wait for the PR to be accepted.

https://github.com/amzn/selling-partner-api-docs/blob/7bfacb95fc9ca2b3335a79acd40846deb3e9a161/guides/use-case-guides/feed-api-upload-invoice-guide-2020-09-04.md

kissn01 commented 3 years ago

@ kissn01有PR的指南,用于上传由@fernlop制作的增值税发票(出色的工作!)。我将直接链接该指南,因此您无需等待PR被接受就可以查看它。

https://github.com/amzn/selling-partner-api-docs/blob/7bfacb95fc9ca2b3335a79acd40846deb3e9a161/guides/use-case-guides/feed-api-upload-invoice-guide-2020-09-04.md

Thanks, @sellerjd . This problem has been solved the reason: In the second step encryptAndUpload_fromString()[encrypt and upload feed data], I read the pdf file as binary and upload it in base format, which caused the Amazon interface to not recognize it. He can only receive byte stream [Byte Array] wrong: pdf --> binary stream / base format correct: pdf --> Byte[] converts the file into a Byte array

thanks again.

biancahuluban commented 3 years ago

Hello everyone,

Just an update: I asked via email the upload invoice team if I can upload multiple invoices per order(because it might be multiple shipments for different order items, or multiple returns...so multiple invoices/credit notes) and they said that we can upload multiple invoices/credit notes for the same order but with a different invoice number!

Happy coding! Bianca Huluban

biancahuluban commented 3 years ago

Hello all,

I receive 403 error, what role should I have for being able to upload the invoices? are there any other requests in order to be able to upload them without 403 result?

sschwarz-allbuyone commented 3 years ago

Hi, i also get the 403 Error on the createFeed method. Do we need the tax-role for uploading? Any updates on this?

paulokow commented 3 years ago

Hi, I'm also getting this error 403

{
      "code": "Unauthorized",
      "message": "Access to the resource is forbidden",
      "details": ""
}

I don't have any privledged role in my profile, however to upload a document I don't need any PII from Amazon, so what's wrong here? Bug?

diegocvazquez commented 3 years ago

@paulokow @allbuyone @biancahuluban Same here 403 any ideas?

biancahuluban commented 3 years ago

We asked amazon Seller Central and we sent an email to upload-your-invoices@amazon.com . No response up to now.

diegocvazquez commented 3 years ago

Hello @biancahuluban, thanks for answering

diegocvazquez commented 3 years ago

Hello everyone, yesterday I got an email from support regarding this issue. I will quote the answer.

.... "Please refer to the official MWS and SP-API documentation to check the up-to-date information, VAT invoice Uploading is not a valid feedtype, currently neither MWS API nor SP API support VAT invoice uploading:"

https://docs.developer.amazonservices.com/en_UK/feeds/Feeds_FeedType.html https://github.com/amzn/selling-partner-api-docs/blob/main/references/feeds-api/feedType_string_array_values.md

paulokow commented 3 years ago

That answer is ridiculous. The feed is mentioned clearly in https://m.media-amazon.com/images/G/03/B2B/invoice-uploader-developer-documentation.pdf

So for sure it's part of MWS API and as MWS is not available anymore, only SP API, then it is kind of natural to expect it supported as well.

diegocvazquez commented 3 years ago

@paulokow Did you make any progress on this? I have tested in MWS and it works, but NOT in SP-API, I think I will reopen the case

paulokow commented 3 years ago

Nope, pls reopen.

diegocvazquez commented 3 years ago

@paulokow I have created a new ticket, did anyone else get this sorted out? @biancahuluban any update?

biancahuluban commented 3 years ago

I did not received any updates regarding this operation. The new SP API should have the existing available operations of the old MWS api!

sh123-987 commented 3 years ago

I'm using this Feed Type and a few weeks ago it was fixed and is now fully working. The process is as follows:

  1. Get URL and encryption details for upload using the createFeedDocument method. You must put "contentType": "application/pdf" in the body of the request.
  2. Encrypt the invoice using AES-CBC with the encryption key and IV received in first step
  3. Upload invoice to the URL received in the first step using a simple PUT request. You must put "Content-Type": "application/pdf" in the headers
  4. Create the feed using the "createFeed" method with the following body:
{
    feedType: "UPLOAD_VAT_INVOICE",
    marketplaceIds: [MARKETPLACEID_OF_ORDER],
    inputFeedDocumentId: documentId, // received in first step
    feedOptions: {
        "metadata:invoicenumber": INVOICE_NUMBER,
        "metadata:orderid": AMAZON_ORDER_ID
        // optional!
        "metadata:totalamount": INVOICE_AMOUNT
        "metadata:totalvatamount": INVOICE_VAT_AMOUNT
    }
}

You will received the FeedID, which you ca use to track if everything worked. As this was not asked in this issue, I won't explain this but here is the code i used in NodeJS usning my own SDK:

const FeedStatus = await amzSDK.request({
    account,
        region: "eu",
        type: "getFeed",
        data: "50653018715",//feedRes[0].feedId,
        accessToken: mwsAccountConfig.accessToken,
        iamUserAuth: auth,
        bottleneckConfig: {
            ...auth.redisAuth
        }
})
console.log(FeedStatus)

const FeedDocument = await amzSDK.request({
    account,
        region: "eu",
        type: "getFeedDocument",
        data: FeedStatus[0].resultFeedDocumentId,
        accessToken: mwsAccountConfig.accessToken,
        iamUserAuth: auth,
        bottleneckConfig: {
            ...auth.redisAuth
        }
})
const FeedDocumentEncryption = {
    iv: Buffer.from(FeedDocument[0].encryptionDetails.initializationVector, 'base64'),
    key: Buffer.from(FeedDocument[0].encryptionDetails.key, 'base64'),
    url: FeedDocument[0].url
}
const FeedDocumentFile = await axios.get(FeedDocumentEncryption.url, {responseType: 'arraybuffer'}).then(r => Buffer.from(r.data, "binary"));
const decryptedFile = await aes.decrypt(FeedDocumentFile, FeedDocumentEncryption.key, {name: 'AES-CBC', iv: FeedDocumentEncryption.iv});
console.log(Utf8ArrayToStr(decryptedFile))

Can you show me your code for how you write the invoice file to the url received from step 3. ("Upload invoice to the URL received in the first step using a simple PUT request. You must put "Content-Type": "application/pdf" in the headers").

I tried using the code Amazon has provided here: https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/use-case-guides/feeds-api-use-case-guide/feeds-api-use-case-guide-2020-09-04.md#encrypt-and-upload-sample-code-java

But the invoice file is corrupted when you try to download it from Amazon. I'm able to upload the invoice file successfully, and when I use the getFeedsReport it tells me the file was successfully processed. But the actual invoice file if you download direct from Amazon is corrupted and unreadable.

diegocvazquez commented 3 years ago

@sh123-987 Do you have a special developer profile for uploading invoices, In my case this is working in MWS but not on SP-API, I have created a case and I was told that the following "Please refer to the official MWS and SP-API documentation to check the up-to-date information, VAT invoice Uploading is not a valid feedtype, currently neither MWS API nor SP API support VAT invoice uploading:"

Do you have an Invoicing profile I am getting an Not authorized error at the last step

thanks for your help

sh123-987 commented 3 years ago

@sh123-987 Do you have a special developer profile for uploading invoices, In my case this is working in MWS but not on SP-API, I have created a case and I was told that the following "Please refer to the official MWS and SP-API documentation to check the up-to-date information, VAT invoice Uploading is not a valid feedtype, currently neither MWS API nor SP API support VAT invoice uploading:"

Do you have an Invoicing profile I am getting an Not authorized error at the last step

thanks for your help

Hi, So the invoice upload comes under the Feeds API, and there are 2 versions. I'm using the newer version (2021/06/30), and its now working for me. You can read this documentation regarding the newer version release: https://github.com/amzn/selling-partner-api-docs/discussions/1107

But to briefly explain the newer version doesn't use encryption/decryption stuff. This document here covers nicely how to set this up via SP-API: https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/use-case-guides/feeds-api-use-case-guide/feeds-api-use-case-guide_2021-06-30.md

The feed type name is "UPLOAD_VAT_INVOICE". For some reason it isn't listed here: https://github.com/amzn/selling-partner-api-docs/blob/main/references/feeds-api/feedtype-values.md

The content-type should be "application/pdf".

If you're getting some authorized error this is either due to when you created your application you need to make sure you tick the necessary permissions and that the seller account of course accepts all those. If not that I believe it was something to do with when you setup your developer account. This documentation should cover the whole permissions stuff when setting up your developer / application: https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/developer-guide/SellingPartnerApiDeveloperGuide.md#registering-as-a-developer

diegocvazquez commented 3 years ago

@sh123-987 Thanks for your response, I am aware about the 2 version, actually I have implemented both versions, and in our application we are generating feeds with success, the issue is only with this type of feed UPLOAD_VAT_INVOICE, we also have PII access, support stated that the feed does no exist, I have insisted and then I was told about a tax role that is requiered for this feed. Are you aware of this tax role? do you have it ? Thanks for your help

sh123-987 commented 3 years ago

@sh123-987 Thanks for your response, I am aware about the 2 version, actually I have implemented both versions, and in our application we are generating feeds with success, the issue is only with this type of feed UPLOAD_VAT_INVOICE, we also have PII access, support stated that the feed does no exist, I have insisted and then I was told about a tax role that is requiered for this feed. Are you aware of this tax role? do you have it ? Thanks for your help

I do have tax roles enabled for my application. "Tax Invoicing - Generate tax invoices to comply with tax regulation."

diegocvazquez commented 3 years ago

@sh123-987 Thanks four help! In our application configuration there are 2 main checkboxes Sellers and providers, we have only sellers clicked but regarding the levels all the checkboxes are clicked, I wonder what is the poviders checkbox

diegocvazquez commented 3 years ago

@sh123-987
I see it is under the developer profile! thanks

12131w commented 2 years ago

您好,您知道如何解决上面提到的403问题吗?由于“禁止访问资源”,我遇到了一些问题。

嗨,我也收到此错误 403

{
      "code": "Unauthorized",
      "message": "Access to the resource is forbidden",
      "details": ""
}

我的个人资料中没有任何特权角色,但是上传文档时我不需要来自 Amazon 的任何 PII,所以这里有什么问题?漏洞?

Hello,do you know how to resove this question?

@sh123-987 我看到它在开发者资料下!谢谢

AnjaEk commented 2 years ago

Hi @12131w , @sh123-987,
did you manage to get an answer/solution to your error? We got the same one when creatFeed is called. Tax permission is set.

Thank you.

biancahuluban commented 2 years ago

Update: We have the feed type in a documentation https://developer-docs.amazon.com/sp-api/docs/tax-invoicing-restricted-role#feeds-reports-and-notifications image

pengjinfei520 commented 2 years ago

Feed Processing Summary:
Number of records processed 1
Number of records successful 0 original-record-number sku error-code error-type error-message1
79525 Error Amazon will generate invoice for shipmentId N/A, orderId N/A

why?

corbin-munce commented 2 years ago

Has anyone outside of Europe got this working?

JohnnyMaxK commented 1 year ago

Feed Processing Summary: Number of records processed 1 Number of records successful 0 original-record-number sku error-code error-type error-message1 79525 Error Amazon will generate invoice for shipmentId N/A, orderId N/A

why?

@pengjinfei520 It's due to the auto invoice generation configured on the Amazon merchant back office. You have to disable it in order to upload your own invoice.

For a French merchant, you will have this answer.

Résumé du traitement des flux :
Nombre d'entrées traitées       1
Nombre d'entrées étant un succès        1

I'm pretty sure that we cannot upload multiple invoices inside the same feed.

Has anyone outside of Europe got this working?

@corbin-munce it's working, I don't have yet the confirmation from the merchant himself but considering the response message from Amazon API. It should be OK.

corbin-munce commented 1 year ago

@Johnny-Bee just to clarify, do you have this working from a country you outside of Europe? Your profile says Paris. I'm in Australia and a year ago Amazon told me that this invoice function is only for Europe.

github-actions[bot] commented 1 year ago

This is a very old issue that is probably not getting as much attention as it deserves. We encourage you to check if this is still an issue after the latest release and if you find that this is still a problem, please feel free to open a new issue and make a reference to this one.

github-actions[bot] commented 1 year ago

closed for inactivity