bent0b0x / amazon-mws

MIT License
14 stars 8 forks source link

Amazon Feed API #9

Open euberdeveloper opened 6 years ago

euberdeveloper commented 6 years ago

I want to use the Amazon Feed API, with POST_ORDER_FULFILLMENT_DATA, the request must contain a body with the order and carrier properties, such as:

`

<!--
$Date: 2005/04/01 $

AMAZON.COM CONFIDENTIAL.  This document and the information contained in it are
confidential and proprietary information of Amazon.com and may not be reproduced, 
distributed or used, in whole or in part, for any purpose other than as necessary 
to list products for sale on the www.amazon.com web site pursuant to an agreement 
with Amazon.com.
-->

<xsd:include schemaLocation="amzn-base.xsd"/>

<xsd:element name="OrderFulfillment">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:choice>
                <xsd:element ref="AmazonOrderID"/>
                <xsd:element ref="MerchantOrderID"/>
            </xsd:choice>
            <xsd:element name="MerchantFulfillmentID" type="IDNumber" minOccurs="0"/>
            <xsd:element name="FulfillmentDate" type="xsd:dateTime"/>
            <xsd:element name="FulfillmentData" minOccurs="0">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:choice>
                            <xsd:element ref="CarrierCode"/>
                            <xsd:element name="CarrierName" type="String"/>
                        </xsd:choice>
                        <xsd:element name="ShippingMethod" type="String" minOccurs="0"/>
                        <xsd:element name="ShipperTrackingNumber" type="String" minOccurs="0"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>

            <xsd:element name="Item" minOccurs="0" maxOccurs="unbounded">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:choice>
                            <xsd:element ref="AmazonOrderItemCode"/>
                            <xsd:element ref="MerchantOrderItemID"/>
                        </xsd:choice>
                        <xsd:element name="MerchantFulfillmentItemID" type="IDNumber" minOccurs="0"/>
                        <xsd:element name="Quantity" type="xsd:positiveInteger" minOccurs="0"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>

        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

</xsd:schema> `

Is your library able to do that? Could you add a parameter to specify the body of the request?

Update: I have looked your code and I guess there is not a way to add the body to the request. So I did a change in my locale project and I added this. Now I can use the method "SubmitFeed" by adding a "body" property and a "contentType" property.

(It's in typescript)

` export default function(initOptions: any) { return function(options) { let method = options.method || 'GET'; let url = 'https://'; url += options.base || 'mws.amazonservices.com'; url += options.endpoint;

    let body = options.body;
    let contentType: string = options.contentType || 'text/plain';

    options.params.AWSAccessKeyId = options.params.AWSAccessKeyId || initOptions.AWSAccessKeyId;
    options.params.SignatureMethod = 'HmacSHA256';
    options.params.SignatureVersion = '2';
    options.params.Timestamp = new Date().toISOString();

    let paramsArr = Object.keys(options.params).map(function(param) {
        return [param, options.params[param]];
    });
    paramsArr.sort(function(a, b) {
        return a[0] > b[0] ? 1 : -1;
    });

    let keys = [];
    let vals = [];
    paramsArr.forEach(function(tuple) {
        keys.push(encodeURIComponent(tuple[0]));
        vals.push(encodeURIComponent(tuple[1]));
    });

    let paramsString = keys.map(function(key, index) {
        return key + '=' + vals[index];
    }).join("&");

    let query = [method, options.base, options.endpoint, paramsString];
    let queryString = query.join('\n');

    let hmac = hmacSHA256(queryString, options.AmzSecretKey || initOptions.AmzSecretKey);
    let signature = base64.stringify(hmac);

    paramsString += '&Signature=' + encodeURIComponent(signature);

    url += '?' + paramsString;

    if (method.toLowerCase == 'post' && body) {
        request.post(url, { body: body, headers: { 'content-type': contentType } }, function(error, response, body) {
            options.callback && options.callback(error, response, body);
        });
    }
    else {
        request[method.toLowerCase()](url, function(error, response, body) {
            options.callback && options.callback(error, response, body);
        });
    }
};

}; `

bhushankummar commented 6 years ago

@euberdeveloper Here is the workaround available. https://www.npmjs.com/package/amazon-mws

bent0b0x commented 5 years ago

Hey @euberdeveloper. Unfortunately I am only able to devote a small amount of time to this repository, so I will only be able to contribute critical bug fixes.

A couple of ways to proceed:

Let me know what you think!