Giter Site home page Giter Site logo

scaleleap / selling-partner-api-sdk Goto Github PK

View Code? Open in Web Editor NEW
65.0 4.0 27.0 8.45 MB

A fully typed TypeScript and Node.js SDK library for Amazon Selling Partner API

Home Page: https://npm.im/@scaleleap/selling-partner-api-sdk

License: MIT License

JavaScript 0.13% TypeScript 99.87%
amazon-selling-partner amazon-sp-api selling-partner-api sp-api amazon-mws

selling-partner-api-sdk's Introduction

Selling Partner API for Node.js

NPM License GitHub Workflow Status Codecov Snyk Semantic Release FOSSA Status


  • A fully typed TypeScript and Node.js SDK package for Amazon Selling Partner API
  • Uses models from API model's repo to generate classes automatically
  • Picks up changes and releases daily when/if models have drifted
  • Based on Axios and uses aws4-axios interceptor to automatically sign the requests
  • Can optionally assume roles via STS, and refresh STS credentials on schedule

Download & Installation

npm i -s @scaleleap/selling-partner-api-sdk

Getting Started

Prerequisites

A few things to get started:

Authorizing Selling Partner API

Note that it is outside the responsibility of this package to handle the authorization process.

This package assumes you have already acquired the access and refresh tokens either by going through the OAuth flow or by using a self-authorized set of credentials.

Basic Usage

Using Existing AWS Credentials

This method is applicable if you want to assume the Selling Partner API role yourself, or you are using a static set of user credentials (not recommended).

import { SellersApiClient } from '@scaleleap/selling-partner-api-sdk'

const stsClient = new STSClient({
  // Static set of credentials that have the permission to assume the role above
  credentials: {
    accessKeyId: 'AKIAIOSFODNN7EXAMPLE',
    secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY',
  },
})

const { Credentials } = await stsClient.send(
  new AssumeRoleCommand({
    // This is the role you have set in your Selling Partner API application
    RoleArn: 'arn:aws:iam::123456789012:role/your-SP-API-role-name',
    RoleSessionName: 'selling-partner-api-axios',
  }),
)

const client = new SellersApiClient({
  accessToken: 'Atza|...',

  // Or use `amazonMarketplaces.CA.sellingPartner.region.endpoint`
  // from `@scaleleap/amazon-marketplaces` package
  basePath: 'https://sellingpartnerapi-na.amazon.com',

  // Or use `amazonMarketplaces.CA.sellingPartner.region.awsRegion`
  // from `@scaleleap/amazon-marketplaces` package
  region: 'us-east-1',

  credentials: {
    accessKeyId: Credentials?.AccessKeyId || '',
    secretAccessKey: Credentials?.SecretAccessKey || '',
    sessionToken: Credentials?.SessionToken || '',
  }
})

const marketplaceParticipations = await client.getMarketplaceParticipations()

Letting @scaleleap/selling-partner-api-sdk to Assume the Role

This package uses aws4-axios under the hood, which has the capability to make the STS call and get the credentials for you, and refresh the temporary AWS credentials session.

import { SellersApiClient } from '@scaleleap/selling-partner-api-sdk'

const client = new SellersApiClient({
  accessToken: 'Atza|...',

  // Or use `amazonMarketplaces.CA.sellingPartner.region.endpoint`
  // from `@scaleleap/amazon-marketplaces` package
  basePath: 'https://sellingpartnerapi-na.amazon.com',

  // Or use `amazonMarketplaces.CA.sellingPartner.region.awsRegion`
  // from `@scaleleap/amazon-marketplaces` package
  region: 'us-east-1',

  // This is the role you have set in your Selling Partner API application
  roleArn: 'arn:aws:iam::123456789012:role/your-SP-API-role-name',

  // Static set of credentials that have the permission to assume the role above
  credentials: {
    accessKeyId: 'AKIAIOSFODNN7EXAMPLE',
    secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY',
  },
})

const marketplaceParticipations = await client.getMarketplaceParticipations()

See the full list of exported classes and types: src/api-models/index.ts.

See @scaleleap/amazon-marketplaces docs for a database of constants about Amazon Marketplaces.

Documentation

Contributing

This repository uses Conventional Commit style commit messages.

Authors or Acknowledgments

License

This project is licensed under the MIT License.

FOSSA Status

selling-partner-api-sdk's People

Contributors

fossabot avatar github-actions[bot] avatar moltar avatar mykelo avatar nguyentoanit avatar renovate-bot avatar renovate[bot] avatar repo-ranger[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

selling-partner-api-sdk's Issues

New sp-ap connection issue

My client provided me grant_type, client_secret, client_id, iamarn and app Name credentials. Are these credentials enough to connect to sp-api via your library?

having all kinds of typescript linting issues

I dont think it has much to do with your plugin but im hoping someone might know why my tsc compiler is freaking out.

when i try to compile my modules which has import { SellersApiClient } from "@scaleleap/selling-partner-api-sdk"; in it. I get several errors like the following.

.../src/modules/amazon-sp-api/lib/typings/index.d.ts:96:16 - error TS2665: Invalid module name in augmentation. Module 'amazon-sp-api' resolves to an untyped module at '.../node_modules/amazon-sp-api/index.js', which cannot be augmented.

.../src/modules/amazon-sp-api/lib/typings/index.d.ts:100:5 - error TS1040: 'async' modifier cannot be used in an ambient context.

.../src/modules/amazon-sp-api/lib/typings/index.d.ts:98:34 - error TS1093: Type annotation cannot appear on a constructor declaration.

my tsconfig

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "allowJs": true,
    "importHelpers": true,
    "jsx": "react",
    "alwaysStrict": true,
    "sourceMap": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitAny": false,
    "noImplicitThis": false,
    "strictNullChecks": false,
    "resolveJsonModule": true,
    "lib": [
      "es2018",
      "dom"
    ]
  },
  "exclude": [
  ],
  "include": [
    // "src/**/*",
    // "src/public/**/*",
    "__tests__/**/*",
    "src"
  ]
}

some versions version

npx tsc -v
Version 4.3.5

npx typescript -v
Version 4.3.5

npm tsc -v
6.9.0

npm typescript -v
6.9.0

npx @types/node -v
v10.16.3

npm @types/node -v
6.9.0

node -v
v10.16.3

package.json

{
  "name": "****",
  "version": "0.0.0",
  "author": "****",
  "license": "Apache-2.0",
  "description": "***",
  "engines": {
    "node": "10.16.3"
  },
  "scripts": {
    "tsc": "./node_modules/.bin/tsc",
    "tscv": "./node_modules/.bin/tsc -v",
    "clean": "rimraf coverage build tmp",
    "build1": "tsc -p tsconfig.release.json",
    "build:watch": "tsc -w -p tsconfig.release.json",
    "dev": "./node_modules/.bin/tsc -w -p tsconfig.release.json",
    "dev2": "nodemon build/src/server.js",
    "dev_debug": "nodemon --inspect=0.0.0.0:9229 build/src/server.js",
    "lint": "tslint -t stylish --project \"tsconfig.json\"",
    "test": "jest --coverage",
    "test:watch": "jest --watch",
    "start": "node src/server.js",
    "startDev": "nodemon build/src/server.js",
    "copy_public": "cp -r src/public build/src/",
    "git": "open https://github.com/ohabash/fornida-api",
    "heroku:restart": "heroku restart -a fornida-api"
  },
  "devDependencies": {
    "@types/bluebird-global": "^3.5.12",
    "@types/cron": "^1.7.2",
    "@types/express": "^4.17.11",
    "@types/jest": "^24.0.18",
    "@types/mongoose": "^5.7.36",
    "@types/node": "^10.14.17",
    "jest": "~24.9.0",
    "prettier": "~1.18.2",
    "rimraf": "^3.0.0",
    "ts-jest": "^24.0.0",
    "tslint": "6.1.3",
    "tslint-config-prettier": "1.18.0",
    "tslint-microsoft-contrib": "~6.2.0",
    "tsutils": "~3.17.0",
    "typescript": "^4.1.5"
  },
  "dependencies": {
    "@scaleleap/selling-partner-api-sdk": "^5.0.0",
    "@types/multer": "^1.4.5",
    "amazon-sp-api": "^0.3.7",
    "ansi-to-html": "^0.6.14",
    "async": "^3.2.0",
    "axios": "^0.19.2",
    "bluebird": "^3.7.2",
    "body-parser": "^1.19.0",
    "bson": "^4.1.0",
    "cheerio": "^1.0.0-rc.3",
    "colors": "^1.3.3",
    "cors": "^2.8.5",
    "cron": "^1.8.2",
    "csv": "^5.3.2",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "express-winston": "^4.0.5",
    "firebase-admin": "^8.9.2",
    "fs": "0.0.1-security",
    "json2csv": "^4.5.3",
    "lodash.orderby": "^4.6.0",
    "moment": "^2.27.0",
    "mongodb": "^3.6.2",
    "mongoose": "^5.10.11",
    "morgan": "^1.9.1",
    "mssql": "^6.2.3",
    "multer": "^1.4.2",
    "node-cron": "^2.0.3",
    "ora": "^4.0.2",
    "path": "^0.12.7",
    "pg": "^7.15.1",
    "promise": "^8.0.3",
    "read-last-lines": "^1.7.2",
    "request": "^2.88.0",
    "request-promise": "^4.2.4",
    "resource-router-middleware": "^0.7.0",
    "rxjs": "^6.5.4",
    "socket.io": "^2.3.0",
    "tough-cookie": "^3.0.1",
    "tslib": "~1.10.0",
    "unirest": "^0.6.0",
    "winston": "^3.3.3",
    "winston-mongodb": "^5.0.5",
    "yargs": "^14.2.0"
  }
}

Unsafe headers

Captura de pantalla 2023-07-10 a las 12 59 35

Hi all!

I follow the steps and appear the "Unsafe headers". It seems like a CORS error but I don't know how to solve this.

Any idea? Thanks :)

Sandbox not working

Good morning,

I see that since a couple of versions ago the isSandbox parameter is no longer present.

I used to make requests in sandbox mode by passing to the configuration parameters the basePath: 'https://sandbox.sellingpartnerapi-eu.amazon.com', but since version 3, using this path returns me the error SellingPartnerInternalServerError.

Any suggestions please?

Thank you very much.

Wrong content type for cancelInboundPlan

Hello, thank you for your awesome package. I just wanted to report a bug in the cancelInboundPlan operation from your newest update, FulfillmentInboundApiClientV20240320. The content type is incorrect and should be set to "application/json; charset=utf-8".

Aplus getContentDocument error

Hello, I'm trying to call getContentDocument for my aplus content but getting error:

SellingPartnerBadRequestError: Unsupported content module type [premium-module-6-three-column-comparison], unable to proceed.
 response: {
      status: 400,
      statusText: 'Bad Request',
      headers: [Object [AxiosHeaders]],
      config: [Object],
      request: [ClientRequest],
      data: [Object]
    }

Fix for api-client-helpers.js file

Please implement on lines 33-40. Didn't have time to put something more official together but will fix the error that is currently getting thrown.

I've added the content-type here Amazon requires.

const { accessToken, credentials, region, roleArn } = exports.ApiClientHelpers.validateRegion(parameters);
			axiosInstance = axios_1.default.create({
				headers: {
					"user-agent": constants_1.USER_AGENT,
					"x-amz-access-token": accessToken !== null && accessToken !== void 0 ? accessToken : "",
					"Content-Type": "application/json; charset=utf-8",
				},
			});

More detailed example for creating client

I'm coming from https://github.com/amz-tools/amazon-sp-api to this project for the type script in this project.

But one thing I'm having trouble with is figuring out how to create the client. With amazon-sp-api, the documentation is very clear on how to create an access token. In fact, the client in that project, the client manages the access token itself, so I don't have to worry about expiration.

With this project it's less clear to me from the docs how to create the access token...some additional documentation would be very helpful.

Which version of the API is used?

Hey,
How do you determine which version of the API to use? For example, the Catalog items API has 3 versions. Do you just pull the latest one? How do know if a new one was released?
I'm asking because we're generating C# code from the models using swagger codegen but we're coming up against this issue.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository. View logs.

  • WARN: Using npm packages for Renovate presets is now deprecated. Please migrate to repository-based presets instead.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): update dependency @types/node to v16.18.97
  • chore(deps): update dependency ts-jest to v29.1.4

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/codecov.yml
  • actions/checkout v4
  • bahmutov/npm-install v1
  • codecov/codecov-action v4
.github/workflows/danger.yml
  • actions/checkout v4
  • bahmutov/npm-install v1
  • danger/danger-js 11.3.1
.github/workflows/generate-models.yml
  • actions/checkout v4
  • actions/checkout v4
  • actions/setup-node v4
  • actions/setup-java v4
  • bahmutov/npm-install v1
  • peter-evans/create-pull-request v6
.github/workflows/release.yml
  • actions/checkout v4
  • actions/setup-node v4
  • bahmutov/npm-install v1
  • nwtgck/actions-netlify v3.0.0
.github/workflows/test.yml
  • actions/checkout v4
  • actions/setup-node v4
  • bahmutov/npm-install v1
  • actions/checkout v4
  • bahmutov/npm-install v1
npm
package.json
  • axios 1.7.2
  • http-status-codes 2.3.0
  • ts-error 1.0.6
  • @apidevtools/swagger-parser 10.1.0
  • @openapitools/openapi-generator-cli 2.13.4
  • @scaleleap/amazon-marketplaces 18.0.1
  • @scaleleap/jest-polly 1.6.17
  • @scaleleap/semantic-release-config 1.1.41
  • @types/fancy-log 2.0.2
  • @types/jest 29.5.12
  • @types/lodash 4.17.4
  • @types/node 16.18.96
  • @typescript-eslint/eslint-plugin 7.11.0
  • @typescript-eslint/parser 7.11.0
  • danger 12.3.0
  • dotenv 16.4.5
  • env-var 7.5.0
  • eslint-config-airbnb-base 15.0.0
  • eslint-config-prettier 9.1.0
  • eslint-import-resolver-typescript 3.6.1
  • eslint-plugin-eslint-comments 3.2.0
  • eslint-plugin-jest 27.9.0
  • eslint-plugin-jest-formatting 3.1.0
  • eslint-plugin-prettier 5.1.3
  • eslint-plugin-simple-import-sort 12.1.0
  • eslint-plugin-sonarjs 0.25.1
  • eslint-plugin-unicorn 53.0.0
  • fancy-log 2.0.0
  • global-agent 3.0.0
  • jest 29.7.0
  • lodash 4.17.21
  • openapi-types 12.1.3
  • rimraf 5.0.7
  • ts-jest 29.1.2
  • ts-morph 22.0.0
  • ts-node 10.9.2
  • ts-node-dev 2.0.0
  • tsconfigs 4.0.2
  • typedoc 0.25.13
  • typescript 5.4.5
nvm
.nvmrc
  • node 16.20.2

  • Check this box to trigger a request for Renovate to run again on this repository

TypeError: Cannot read property 'every' of undefined

Getting the following errors on the latest version:

{
  "errorType": "TypeError",
  "errorMessage": "Cannot read property 'every' of undefined",
  "trace": [
    "TypeError: Cannot read property 'every' of undefined",
    "    at Function.isAPIModelError (/node_modules/@scaleleap/selling-partner-api-sdk/src/helpers/api-client-helpers.ts:34:91)",
    "    at null.<anonymous> (/node_modules/@scaleleap/selling-partner-api-sdk/src/helpers/api-client-helpers.ts:73:30)",
    "    at processTicksAndRejections (internal/process/task_queues.js:95:5)",

    "    at null.runRequest (/node_modules/@middy/core/index.js:86:26)"
  ]
}

FbaInventoryApiClient.getInventorySummaries()

I'm trying to call getInventorySummaries() but am unsure what to pass in for the granularityType parameter. I tried to set it as type Marketplace but get this error:

Type 'Marketplace' is not assignable to type '"Marketplace"'.

Do you have any examples of how to call getInventorySummaries()?

[Vendor Orders API] includeDetails flag in getPurchaseOrders not working

Hi,

I just wanted say this is a fantastic module. Thank you for this!

When includeDetails is set to false, order details are always returned when I call the getPurchaseOrders.

Here is my configuration.

import { VendorOrdersApiClient } from '@scaleleap/selling-partner-api-sdk'

const client = new VendorOrdersApiClient({
accessToken: 'Atza|.....',

// Or use amazonMarketplaces.CA.sellingPartner.region.endpoint
// from @scaleleap/amazon-marketplaces package
basePath: 'https://sandbox.sellingpartnerapi-na.amazon.com',

credentials: {
accessKeyId: 'XXXXXX',
secretAccessKey: 'XXXXXXX',
},

// Or use amazonMarketplaces.CA.sellingPartner.region.awsRegion
// from @scaleleap/amazon-marketplaces package
region: 'us-east-1',
})

const purchaseOrderOptions = {
createdBefore: '2019-09-21T00:00:00',
createdAfter: '2019-08-20T14:00:00',
includeDetails: false,
nextToken: 'MDAwMDAwMDAwMQ==',
sortOrder: 'DESC'
}
const purchaseOrders = await client.getPurchaseOrders(purchaseOrderOptions);
console.log(nextToken: ${purchaseOrders.data.payload.pagination.nextToken});
console.log(purchaseOrders.data.payload.orders);

According to the docs, I should be getting just the Purchase Order Numbers but the order details are included.

Thanks in advance.

How often do we release new version?

Hi there. I’m wondering when will the next version get release? I’ve been waiting for the new listing item api for a week. The model PR was merged last week. I thought the release is automated once model updates but looks like it’s not.

RDT for getOrders and getOrderItems

Hi folks,

The API is recommending that these calls use the RDT. Is using the RDT something that this sdk handles or is that something that the developer has to implement on top of this sdk?

Thanks!

Using Shipping API v2

Hello. This library is the closest I have been to make Amazon's Shipping API work, but the ShippingAPIClient class only allows to make calls to Shipping API v1, would it be possible to make it work for Shipping API v2?

Many thanks.

How to unzip the report document?

How to unzip report document using node js that is compressed in gzip?

Tried to use zlib but the file is encrypted and unable to unzip it (gunzip)

My current script
image

Sample output of the gzip file
\u001f�\b\u0000\u0000\u0000\u0000\u0000\u0000\u0000��r�X�(���\nuE���X@�.���\u001d\u0006|\u0007\u001b\u001bl�O�8!@6z\u0006DK"�t���\u000f���?���

Shipping-API getRates has v2

I'm raising this issue as I try to get more data from Amazon. But for the shipping api, the getRates call, there is a required field channelDetails which is not present in the swagger, and therefore not here either.

However, I think if possible, we should get ahead of this. Here is the response from Amazon in our ticket.

The swagger you have provided is for the v1 getRates API. We have upgraded to v2 getRates API for which this channelDetails field is mandatory, but we are still supporting the older v1 APIs. For v1 APIs, channelDetails parameter is not available.

I don't see v2 anywhere, I don't see different swagger anyway. So trying to figure that out.

export all enums

image

I think it would be nice to import types/enums from root

import { OrderOrderStatusEnum,  or whatever enums/types/interfaces } from '@scaleleap/selling-partner-api-sdk';

or maybe use string/number literal types instead of enums

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.