npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mws-sdk-async

v0.11.1

Published

A simple class based approach to work with Amazon's Merchant Web Services APIs.

Downloads

40

Readme

Amazon Merchant Web Services (MWS) Async/Await library

This package is in alpha phase and does not have full support for all MWS APIs. Use at your own risk.

The MWS library is notoriously difficult to work with especically with a language like javascript, that doesn't natively support xml.

This library is the product of working for an ecommerce company that sells on Amazon as a key part of the business.

Getting started

You can get access to each available service by destructuring it off of the main body.

  const { Orders, Products } = require('mws-sdk-async');

Each API is a a constructor that take accepts a configuration object that follows this format.

  const config = {
    mwsHost, // -- optional, defaults to mws.amazonservices.com
    marketplaceId, // -- required, used as the default in each call unless specifically provided
    sellerId, // -- required
    authToken, // -- required
    accessKeyId, // -- required
    secretKey // -- required
  };

  const api = new Orders(config);

Alternately, you may use environment variabes to set up your configuration. The constructor will look for the following environment variables.

process.env.MWS_HOST // defaults to mws.amazonservices.com
process.env.MWS_MARKETPLACE_ID // required
process.env.MWS_SELLER_ID // required
process.env.MWS_AUTH_TOKEN // required
process.env.MWS_ACCESS_KEY // required
process.env.MWS_SECRET_KEY // required

Orders API

Base documentation http://docs.developer.amazonservices.com/en_US/orders-2013-09-01/index.html

List Orders

Throttling: Max request quota: 6, restore rate: 1 request per minute

  let orders = await mws.listOrders({
    CreatedAfter, // optional (see note below), ISO formatted date
    CreatedBefore, // optional (see note below), ISO formatted date
    LastUpdatedAfter, // optional (see note below), ISO formatted date
    LastUpdatedBefore, // optional (see note below), ISO formatted date
    OrderStatus, // optional, *array* containing 1 or more order status
    MarketplaceId, // optional, an *array* of marketplaces -- defaults to the one you specified in your configuration
    FulfillmentChannel, // optional, an *array* containing one or both of: AFN (fulfilled by amazon) or MFN (fulfilled by merchant)
    PaymentMethod, // optional
    BuyerEmail, // optional
    SellerOrderId, // optional
    MaxResultsPerPage, // optional
    TFMShipmentStatus // optional, only available in china
  });
  • Dates: You must either specific a CreatedAfter and CreatedBefore timestamp or a LastUpdatedAfter/LastUpdatedBefore timestamp, but not both.

  • ISO Format: ISO Format in MWS

  • Order Status enumeration:

    • PendingAvailable (preorder - only available in japan)
    • Pending (payment not completed)
    • Unshipped (must be used together with PartiallyShipped)
    • Shipped
    • InvoiceUnconfirmed (china only)
    • Cancelled
    • Unfulfillable (Amazon fulfilled orders only)

Response

{
  NextToken,
  Orders: [
    {
      LatestShipDate,
      OrderType,
      PurchaseDate,
      AmazonOrderId,
      BuyerEmail,
      IsReplacementOrder,
      LastUpdateDate,
      NumberOfItemsShipped,
      ShipServiceLevel,
      OrderStatus,
      SalesChannel,
      ShippedByAmazonTFM,
      IsBusinessOrder,
      LatestDeliveryDate,
      NumberOfItemsUnshipped,
      PaymentMethodDetails: { PaymentMethodDetail }
      BuyerName,
      EarliestDeliveryDate,
      OrderTotal: {
        CurrencyCode,
        Amount
      },
      IsPremiumOrder,
      EarliestShipDate,
      MarketplaceId,
      FulfillmentChannel,
      PaymentMethod,
      ShippingAddress: {
        City,
        AddressType,
        PostalCode,
        StateOrRegion,
        Phone,
        CountryCode,
        Name,
        AddressLine1,
        AddressLine2
      },
      IsPrime,
      ShipmentServiceLevelCategory,
      SellerOrderId
    },
  ...
  ]
}

List Orders By Next Token

Throttling: Max request quota: 6, restore rate: 1 request per minute -- Shared with ListOrders

let orders = await mws.listOrdersByNextToken(NextToken);

Response: Same as ListOrders

List Order Items

Throttling: Max request quote: 30, restore rate: 2 requests per second

let items = await mws.listOrderItems(AmazonOrderId);

Response

{
  AmazonOrderId,
  OrderItems: [
    {
      QuantityOrdered,
      Title,
      ShippingTax: {
        CurrencyCode,
        Amount
      },
      PromotionDiscount: {
        CurrencyCode,
        Amount
      },
      ConditionId,
      IsGift,
      ASIN,
      SellerSKU,
      OrderItemId,
      ProductInfo: {
        CurrencyCode,
        Amount
      },
      GiftWrapTax: {
        CurrencyCode,
        Amount
      },
      QuantityShipped,
      ShippingPrice,
      GiftWrapPrice,
      ConditionSubtypeId,
      ItemPrice: {
        CurrencyCode,
        Amount
      },
      ItemTax: {
        CurrencyCode,
        Amount
      },
      ShippingDiscount: {
        CurrencyCode,
        Amount
      }
    }
  ]
}

Products API

Base Products Documentation: https://developer.amazonservices.com/gp/mws/api.html/146-8039497-2146729?ie=UTF8&group=products&section=products&version=latest

Get Service Status

Usage

let response = await mws.getServiceStatus();

Response

{
  Status: 'GREEN', // or 'RED'
  Timestamp
}

Get Competitive Price for SKU

Usage

getCompetitivePriceForSKUs accepts an array of Amazon Seller SKUs present within your amazon store.

** Note: The sku list must contain at least 1 sku and can not contain more than 20 skus.

let response = await MWS.getCompetitivePriceForSKUs([ 'sku1', 'sku2', ... ]);
[
  {
    SellerSKU,
    Product: {
      Identifiers: {
        MarketplaceASIN: {
          MarketplaceId,
          ASIN
        }
        SKUIdentifier: {
          MarketplaceId,
          SellerId,
          SellerSKU
        }
      },
      CompetitivePricing: [
        {
          CompetitivePriceId,
          Condition,
          Subcondition,
          LandedPrice: {
            CurrencyCode,
            Amount
          },
          ListingPrice: {
            CurrencyCode,
            Amount
          },
          Shipping: {
            CurrencyCode,
            Amount
          }
        }
      ]
    }
  }
]