bhushankummar / amazon-mws

Amazon MWS NodeJS Wrapper
MIT License
197 stars 78 forks source link

Invoice Upload Feed: Pass feed options #116

Closed florianbepunkt closed 4 years ago

florianbepunkt commented 4 years ago

I am trying to implement the upload of invoices, following the Invoice Uploader Developer Guide. In order to upload an invoice, the feed content needs to be pdf file. Besides that I also should pass InvoiceNumber and OrderId as Feed Options. How do I pass feed options with this lib? I only saw feed content in the example. Thank you

bhushankummar commented 4 years ago

@florianbepunkt Can you point out to the MWS Documentation and Sample of the PDF?

wangjue666 commented 4 years ago

You can look it up https://images-cn.ssl-images-amazon.com/images/G/28/rainier/help/XML_Documentation_Intl.V158771171.pdf

florianbepunkt commented 4 years ago

@bhushankumarl I don't know why, but this functionality is not in the regular MWS reports api, but amazon has its own develoepr guide published for it: https://m.media-amazon.com/images/G/03/B2B/invoice-uploader-developer-documentation.pdf

I have a working implementation in a production environment where I construct the requests manually, since I cannot do it with this lib. Although it works like a charm, it would be nice to use one lib for all mws related requests.

wangjue666 commented 4 years ago

It was more than a decade ago, What else can we say

bhushankummar commented 4 years ago

@florianbepunkt Can you share that sample?

Email: bhushankumar.lilapara@gmail.com

florianbepunkt commented 4 years ago

@bhushankumarl I'am afraid I can't share any of my project. But there is really nothing special to this api. It's a regular call to the submit feed api, just with other params (as outlined in the pdf i linked above).

bhushankummar commented 4 years ago

@florianbepunkt @wangjue666

Try this way, and let me know how it's gone.

    const FeedContent = fse.readFileSync('./invoice.pdf', 'UTF-8');
    console.log('FeedContent ', FeedContent);
    const mwsRequestData = {
        Version: '2009-01-01',
        Action: 'SubmitFeed',
        FeedType: '_UPLOAD_VAT_INVOICE_',
        FeedContent: FeedContent,
        SellerId: 'SELLER_ID',
        MWSAuthToken: 'MWS_AUTH_TOKEN',
        'MarketplaceIdList.Id.1': 'MarketplaceIdList.Id.1',
        'metadata.OrderId': 'OrderId',
        'metadata.InvoiceNumber': 'InvoiceNumber',
        'metadata.TotalAmount': 'TotalAmount',
        'metadata.VATAmount': 'VATAmount',
        'metadata.DocumentType': 'DocumentType', //'Invoice' , 'CreditNote'
    };
    try {
        const response = await amazonMws.feeds.submit(mwsRequestData);
        console.log('response', response);
    } catch (error) {
        console.log('error ', error);
    }

Please feel free to reopen the issue, if the error still persists.

danielecr commented 3 years ago

Sorry. NO this does not work.

I have some additional information about it. A working implementation (in PHP), call this url:

/?Action=SubmitFeed&Merchant=[merchant]&MarketplaceIdList.Id.1=[marketplaceid]&FeedType=_UPLOAD_VAT_INVOICE_&PurgeAndReplace=false&MWSAuthToken=[mwsauthtoken]&ContentMD5Value=[md5]&FeedOptions=metadata%3Ashippingid%3D[shipid]%3Bmetadata%3Aorderid%3D[orderid]&AWSAccessKeyId=[accesskey]....

so, FeedOptions is a string, as you see in the linked document:

feedOptions.put("metadata:OrderId", "XXX-XXXXXXX-XXXXXXX");
 feedOptions.put("metadata:TotalAmount", String.format(TOTALAMMOUNT));
 feedOptions.put("metadata:TotalVATAmount", String.format(TOTALVATAMMOUNT));
 feedOptions.put("metadata:InvoiceNumber", INVOICE_NUMBER);
 String options = feedOptions.entrySet().stream()
 .map(e -> String.format("%s=%s", e.getKey(), e.getValue()))
 .collect(Collectors.joining(";"));

it means a string formatted as metadata:[meta1]=[value1];metadata:[meta2]=[value2];..., so a right direction is to specify

const mwsRequestData = {
        Version: '2009-01-01',
        Action: 'SubmitFeed',
        FeedType: '_UPLOAD_VAT_INVOICE_',
        FeedContent: FeedContent,
        SellerId: 'SELLER_ID',
        MWSAuthToken: 'MWS_AUTH_TOKEN',
        'MarketplaceIdList.Id.1': 'MarketplaceIdList.Id.1',
       'FeedOptions':"metadata:orderid=OrderId;metadata:InvoiceNumber=InvoiceNr;metadata:...."
    };

This API call should be not listed in documentation, unless someone REALLY confirms it works.

for document upload it should call the url / without appending version