@amazon-sp-api-release/amazon-sp-api-sdk-js 1.0.0-rc7 → 1.0.0-rc8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
## JavaScript SDK for Selling Partner API
|
|
2
|
+
[](https://www.npmjs.com/package/@amazon-sp-api-release/amazon-sp-api-sdk-js)
|
|
3
|
+
|
|
4
|
+
<!-- youtube video is under creating -->
|
|
5
|
+
<!-- [](https://www.youtube.com/watch?v=OmYTAA80V_4)
|
|
6
|
+
|
|
7
|
+
*Click on the image to watch the video.* -->
|
|
8
|
+
|
|
9
|
+
The Selling Partner API SDK for JavaScript enables you to easily connect your JavaScript/Node.js application to Amazon's REST-based Selling Partner API.
|
|
10
|
+
|
|
11
|
+
* [Learn more about Selling Partner API](https://developer.amazonservices.com/)
|
|
12
|
+
* [Selling Partner API Documentation](https://developer-docs.amazon.com/sp-api/)
|
|
13
|
+
|
|
14
|
+
### Getting started
|
|
15
|
+
|
|
16
|
+
#### Credentials
|
|
17
|
+
|
|
18
|
+
Before you can use the SDK, you need to be registered as a Selling Partner API developer. If you haven't done that yet, please follow the instructions in the [SP-API Registration Overview](https://developer-docs.amazon.com/sp-api/docs/sp-api-registration-overview).
|
|
19
|
+
You also need to register your application to get valid credentials to call SP-API. If you haven't done that yet, please follow the instructions in [Registering your Application](https://developer-docs.amazon.com/sp-api/docs/registering-your-application).
|
|
20
|
+
If you are already registered successfully, you can find instructions on how to view your credentials in [Viewing your Application Information and Credentials](https://developer-docs.amazon.com/sp-api/docs/viewing-your-application-information-and-credentials).
|
|
21
|
+
|
|
22
|
+
#### Minimum requirements
|
|
23
|
+
|
|
24
|
+
To run the SDK you need Node version 14 or higher.
|
|
25
|
+
|
|
26
|
+
#### Install the SDK
|
|
27
|
+
|
|
28
|
+
1. Find the latest version number [here](https://github.com/amzn/selling-partner-api-sdk/releases).
|
|
29
|
+
2. Add the dependency to your project (see instructions for [npm](#using-npm), [yarn](#using-yarn) and [Add as an package dependency](#add-as-an-package-dependency) below).
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
##### Using npm:
|
|
33
|
+
```bash
|
|
34
|
+
npm install @amazon-sp-api-release/amazon-sp-api-sdk-js
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
##### Using yarn:
|
|
38
|
+
```bash
|
|
39
|
+
yarn add @amazon-sp-api-release/amazon-sp-api-sdk-js
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
##### Add as a package dependency
|
|
43
|
+
Add the following line to the `dependencies` in your `package.json` file:
|
|
44
|
+
```bash
|
|
45
|
+
"@amazon-sp-api-release/amazon-sp-api-sdk-js": "^1.0.0"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Use the SDK
|
|
49
|
+
|
|
50
|
+
In order to call one of the APIs included in the Selling Partner API, you need to:
|
|
51
|
+
1. Configure credentials (Note: Use your individual credentials for `clientId`, `clientSecret` and `refreshToken`)
|
|
52
|
+
2. Enable auto `accessToken` retrievel using our built in ApiClient function OR retrieve `accessToken` using our `LwaAuthClient` helper (Be aware for some APIs, you will need extra step to get `RDT Token`)
|
|
53
|
+
2. Create an instance for a specific API and API client, then apply `accessToken` to it.
|
|
54
|
+
3. Call an API operation
|
|
55
|
+
|
|
56
|
+
For an example, refer to the following sample code for connecting to Sellers API:
|
|
57
|
+
|
|
58
|
+
```javascript
|
|
59
|
+
import {
|
|
60
|
+
SellersSpApi
|
|
61
|
+
} from '@amazon-sp-api-release/amazon-sp-api-sdk-js';
|
|
62
|
+
|
|
63
|
+
async function getMarketplaceParticipations() {
|
|
64
|
+
try {
|
|
65
|
+
//Configure Sellers ApiClient
|
|
66
|
+
const sellersApiClient = new SellersSpApi.ApiClient(AppConfig.spApiNAEndpoint);
|
|
67
|
+
sellersApiClient.enableAutoRetrievalAccessToken('<YOUR_CLIENT_ID>','<YOUR_CLIENT_SECRET>', '<YOUR_REFRESH_TOKEN>' null);
|
|
68
|
+
const sellersApi = new SellersSpApi.SellersApi(sellersApiClient);
|
|
69
|
+
|
|
70
|
+
//Call GetMarkerplaceParticipations API
|
|
71
|
+
const participations = await sellersApi.getMarketplaceParticipations();
|
|
72
|
+
console.log(
|
|
73
|
+
JSON.stringify(participations, null, ' ') +
|
|
74
|
+
'\n**********************************'
|
|
75
|
+
)
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error('Exception when calling getMarketplaceParticipations API', error.message);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
getMarketplaceParticipations();
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Alternatively, you can go to `@amazon-sp-api-release/amazon-sp-api-sdk-js/sample-node-app` and copy over and modify `index.js` and `app.config.mjs` files and give them a try. You can see multiple API operation call sampleswith various way of retrieving token, as well how to set up rate limiter and retry logic when making API calls.
|
|
85
|
+
|
|
86
|
+
##### Additional Note:
|
|
87
|
+
This Amazon Selling Partner API JavaScript SDK is fully compatible with ECMAScript modules (ESM). You can use modern ES6+ import/export syntax as demonstrated in the example code:
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
import {
|
|
91
|
+
SellersSpApi,
|
|
92
|
+
} from '@amazon-sp-api-release/amazon-sp-api-sdk-js';
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Giving Feedback
|
|
96
|
+
|
|
97
|
+
We need your help in making this SDK great. Please participate in the community and contribute to this effort by submitting issues, participating in discussion forums and submitting pull requests through the following channels:
|
|
98
|
+
|
|
99
|
+
Submit [issues](https://github.com/amzn/selling-partner-api-sdk/issues/new/choose) - this is the preferred channel to interact with our team
|
|
100
|
+
Articulate your feature request or upvote existing ones on our [Issues][sdk-issues] page
|
|
101
|
+
|
|
102
|
+
[sdk-issues]: https://github.com/amzn/selling-partner-api-sdk/issues
|
|
103
|
+
|
|
104
|
+
|