This repository was created by using Amazon's JavaScript SDK for Node.js by following the Tutorial: Automate your SP-API Calls Using a JavaScript SDK for Node.js.
npm install git+git@github.com:xcellentexchange/amazon-spapi.git
import { SellersApi, ApiClient as SellersApiClient } from 'amazon-spapi/sdk/src/sellers/index.js'
const sellerApiClient = new SellersApiClient('https://sellingpartnerapi-na.amazon.com')
const sellerApi = new SellersApi(sellerApiClient)
sellerApiClient.enableAutoRetrievalAccessToken('<client ID>', '<client secret>', '<refresh token>')
const participations = await sellerApi.getMarketplaceParticipations()
import { OrdersV0Api, ApiClient as OrdersApiClient } from 'amazon-spapi/sdk/src/ordersV0/index.js'
const ordersApiClient = new OrdersApiClient('https://sellingpartnerapi-fe.amazon.com')
ordersApiClient.enableAutoRetrievalRestrictedDataToken('<client ID>', '<client secret>', '<refresh token>', ['buyerInfo', 'shippingAddress'])
const ordersApi = new OrdersV0Api(ordersApiClient)
const order = await ordersApi.getOrder('<order ID to retrieve>')
In case you manage LWA token refresh flow, you can explicitly use the access token you got yourself for your SP-API call as follows.
import { SellersApi, ApiClient as SellersApiClient } from 'amazon-spapi/sdk/src/sellers/index.js'
const sellerApiClient = new SellersApiClient('https://sellingpartnerapi-fe.amazon.com')
const sellerApi = new SellersApi(sellerApiClient)
sellerApiClient.applyXAmzAccessTokenToRequest('<access token you retrieve yourself>')
const participations = await sellerApi.getMarketplaceParticipations()
The following code shows how to use LwaAuthClient
to execute token refresh flow.
import { LwaAuthClient } from 'amazon-spapi/src/helper/LwaAuthClient.mjs'
const lwaClient = new LwaAuthClient('<client ID>', '<client secret>', '<refresh token>')
const accessToken = await lwaClient.getAccessToken()