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

sp-api-node

v3.0.0

Published

🛡 Fully typesafe Amazon Selling Partner API SDK for Node.js

Downloads

581

Readme

Some of the features

  • 🛡 Fully typesafe with Amazon official definitions
  • 🔄 Auto-updated with the latest model changes
  • ⚡️ Auto-retrying requests when rate limited
  • ⚔️ Authentication out of the box

Installation

yarn add sp-api-node
# or with npm
npm install sp-api-node

Before starting

In order to use the Selling Partner API, you need to register as a developer and register your application. Follow Amazon's docs on getting started with the Selling Partner API and obtaining a refresh token for your application.

Authentication

This SDK handles authentication for you and takes care of both acquiring an access token and assuming the role via STS, as well as keeping the credentials refreshed. The client expects the following credentials:

Usage

Client options

| option | description | required | default | | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------- | -------- | ------- | | region | The region for the Selling Partner API (see SP-API Endpoints) | yes | - | | debug | Log additional information like requests, authorization triggers, rate-limits, etc. | no | false | | handleRateLimits | If the client should intercept rate-limited requests and wait the appropriate time before retrying the request | no | true | | defaultRateLimitWaitSeconds | How many seconds to wait by default if a request is rate limited and the client doesn't have information about the restore rate | no | 60 | | credentials | Credentials for calling the SP API (see Authentication) | yes | - |

Calling the API

Import the client

import SellingPartner from "sp-api-node";

Create a new instance

const sp = new SellingPartner({
  region: "eu-west-1",
  credentials: {
    clientId: "amzn1.application-oa2-client.example",
    clientSecret: "050e346ef80574b4c3example",
    roleArn: "arn:aws:iam:3513513:role/SP-API-Example-Role",
    accessKey: "AKIAU420PEXAMPLE",
    secretKey: "53fac/51767+CJCo4/9aGexample",
    refreshToken: "Atzr|Ra55Kfgu-_...B03lexample",
    roleSessionName: "sp-api-node",
  },
});

Now all APIs are available as properties from the instance you just created. APIs that have only one version are accessible directly, while the ones that have multiple versions are accessible via theApi.vVersion.theMethod().

// Single version

const participations = await sp.sellers.getMarketplaceParticipations();

// With multiple versions

const item = await sp.catalogItems.v0.getCatalogItem("my-asin", {
  MarketplaceId: "my-mkt-id",
});

Accessing types for each endpoint

If you any of the types of a specific endpoint, you can import them through their dedicated path at sp-api-node/<api>/<version?>.

import type { Marketplace } from "sp-api-node/sellers";
import type { Order, OrderItem } from "sp-api-node/orders/v0";

Handling rate limits

This SDK automatically handles rate limits and waits for the necessary amount of time by reading the x-amzn-RateLimit-Limit header. See Usage Plans and Rate Limits in the SP-API.

When Amazon replies with a QuotaExceeded error, the client will determine how many seconds are left before being able to retry the request without being rate-limited and stop execution for that amount of time.

If you want to prevent this type of behavior and have the client throw the QuotaExceeded error instead of waiting, pass handleRateLimits: false to the client constructor.

TypeScript support

This client is fully written in TypeScript, by transforming the Amazon OpenAPI models into TypeScript definitions using the amazing acacode/swagger-typescript-api library.

Getting the latest model updates

A Github Action runs every 30 minutes and gets the latest models from amzn/selling-partner-api-models. If there's any changes in the generated client, updates will be pushed a new version will be released ensuring we always work with the latest models.

License

MIT