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

@lemay/mws-api-lite

v1.1.11

Published

Lightweight Amazon MWS API Client

Downloads

10

Readme

travis-ci-status npm version npm downloads

Introduction

This is a light-weight javascript library for Amazon Marketplace Web Service(Amazon MWS) APIs. It is said to be lite-weight because it only provides essentials to use Amazon MWS, it doesn't provide abstract API data types.

This library could run under several Javascript environments like:

  • Node.js
  • Web Pages(useless in most cases due to the cross domain request restriction)
  • Browser Extensions(you need to add the mws endpoint urls to manifest.json to allow access)
  • Google App Scripts, not working due to GAS runtime issues and bugs at the moment

Nodejs

Install

npm install --save @lemay/mws-api-lite

Usage

There are three API signatures in this client:

// For API without body data, use this
apiName(params, callback);

// For special API SubmitFeed or any API that has request body, use this one, body should be a js string, client will do the encoding
apiName(params, body, callback);

// For special API GetServiceStatus, use this, the first parameter is the section name API, with whitespace striped
// it could be "Orders", "Products", "FulfillmentOutboundShipment", "Reports" etc
apiName('Orders', callback);

the callback is a standard Node.js style callback, first parameter is err, and second one is response, always compare err with null to check error, sometimes the api call may also throw an error, so a try catch block is recommended.

params is a api request parameter object, e.g. {"CreatedAfter": '2017-10-20T00:00:00Z', "MarketplaceId.Id.1": MWSClient.getMarketplaceId('US')}, when there are no request parameters, use a blank object {}.

Since marketplace id is used all the time in MWS APIs, we provide a special class method getMarketplaceId(), it takes a country code like CN, US, JP, FR etc, and will return the corresponding Amazon marketplace id, see examples below.

Examples

Create and initialize an mws client instance:

const MWSClient=require('@lemay/mws-api-lite').NodeJSMWSClient;
const client_auth = new MWSClient('US', '<your-access-id>', '<your-mws-access-secret>', '<your-seller-id>', '<your-mws-auth-token-optional>');

Get Orders Service Status:

client_auth.GetServiceStatus('Orders', function(err, res){
  if(err){
    console.log(err);
  } else {
    console.log(res);
  }
});

List recent orders:

client_auth.ListOrders({"CreatedAfter": '2017-10-20T00:00:00Z', "MarketplaceId.Id.1": MWSClient.getMarketplaceId('US')}, function(err, res){
  if(err){
    console.log(err);
  } else {
    console.log(res.body);
  }
});

Submit an xml price feed:

var xml=`
<?xml version="1.0" encoding="UTF-8"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
  <Header>
    <DocumentVersion>1.01</DocumentVersion>
    <MerchantIdentifier>SOME-ID</MerchantIdentifier>
  </Header>
  <MessageType>Price</MessageType>
  <Message>
    <MessageID>1</MessageID>
      <Price>
        <SKU>SKU-OH7O</SKU>
        <StandardPrice currency="USD">13.80</StandardPrice>
      </Price>
  </Message>
</AmazonEnvelope>
`;

client_auth.SubmitFeed({FeedType: '_POST_PRODUCT_PRICING_DATA_', "MarketplaceIdList.Id.1": MWSClient.getMarketplaceId('US'), }, xml, function(err, res){
  if(err){
    console.log(err);
  } else {
    console.log(res);
  }
});

Submit a flat file(tsv) feed:

const fs=require('fs');
const path=require('path');
const tsv=fs.readFileSync(path.join(__dirname, 'data.tsv'), {encoding: 'utf8'});

client_auth.SubmitFeed({FeedType: '_POST_FLAT_FILE_LISTINGS_DATA_', "MarketplaceIdList.Id.1": MWSClient.getMarketplaceId('US')}, tsv, function(err, res){
  if(err){
    console.log(err);
  } else {
    console.log(res.body);
  }
});

Browser or Browser extensions

Use <script> tag with jsDelivr CDN:

<script src="https://cdn.jsdelivr.net/npm/@lemay/mws-api-lite@latest/browser/bundle.min.js"></script>
<script>
var client = new WebBrowserMWSClient(...);
</script>

Or download the pre-built version from jsDelivr.com, then put it into your web page(will not work due to cross domain request restriction) or extension.

Google Apps Script(GAS)

GAS version is not working due to some GAS runtime issues and bugs.

var client = new GoogleAppsScriptMWSClient(...);

Download the pre-built version from jsDelivr.com.