AmzSpApi 0.0.3
See the version list below for details.
dotnet add package AmzSpApi --version 0.0.3
NuGet\Install-Package AmzSpApi -Version 0.0.3
<PackageReference Include="AmzSpApi" Version="0.0.3" />
paket add AmzSpApi --version 0.0.3
#r "nuget: AmzSpApi, 0.0.3"
// Install AmzSpApi as a Cake Addin #addin nuget:?package=AmzSpApi&version=0.0.3 // Install AmzSpApi as a Cake Tool #tool nuget:?package=AmzSpApi&version=0.0.3
AmazonSpAPI
AmazonSpAPI is a c# library organize and generate SP-API request.
Installation
Build the project AmzSpAPi and find assembly file AmzSpApi.dll with your project.
Getting Started
Before you can use the client you need to add your app client and aws user credentials.
Setting credentials from configuration file
You could use encoded string value with base64 encode.
<add key="SELLING_PARTNER_APP_CLIENT_ID" value="<YOUR_APP_CLIENT_ID>" />
<add key="SELLING_PARTNER_APP_CLIENT_SECRET" value="<YOUR_APP_CLIENT_ID>" />
<add key="AWS_ACCESS_KEY_ID " value="<YOUR_APP_CLIENT_ID>" />
<add key="AWS_SECRET_ACCESS_KEY " value="<YOUR_APP_CLIENT_ID>" />
<add key="AWS_SELLING_PARTNER_ROLE" value="<YOUR_APP_CLIENT_ID>" />
var config = new Config()
{
Region = SpApiRegion.FarEast,
RefreshToken = "<Refresh Token>",
Options = new Options()
{
OnlyGrantlessOperations = false,
UseConfigurationCredential = true
}
};
var api = new SellingPartnerApi(config);
Setting credentials from configuration object
var config = new Config()
{
Region = SpApiRegion.FarEast,
RefreshToken = "<Refresh Token>",
Credentials = new Credentials()
{
AppClient = new AppClient()
{
Id = "<LWA client id>",
Secret = "<LWA client secret>",
},
AwsUser = new AwsUser()
{
Id = "<Aww User Id>",
SecretKey = "<Aws User Secret Key>",
Role = "<Aws User Role Arn>"
},
},
Options = new Options()
{
OnlyGrantlessOperations = false,
}
};
Config params
{
Region='<REGION>',
RefreshTToken='<REFRESH_TOKEN>',
AccessToken='<ACCESS_TOKEN>',
RoleCredentials:{
Id='<TEMPORARY_ROLE_ACCESS_ID>',
Secret='<TEMPORARY_ROLE_ACCESS_SECRET>',
SecurityToken='<TEMPORARY_ROLE_SECURITY_TOKEN>'
},
Credentials:{
AppClient:{
Id="<APP_CLIENT_ID>",
Secret= "<APP_CLIENT_SECRET>"
},
AwsUser = {
Id = "<AWS_USER_ID>",
Secret = "<AWS_USER_SECRET>",
UserRole = "<AWS_SELLING_PARTNER_API_ROLE>"
}
},
Options:{
UseConfigurationCredential = true
UseSandbox:false,
OnlyGrantlessOperations:false
}
}
Valid properties of the config object:
Name | Type | Default | Description |
---|---|---|---|
Region<br>required | string | - | The region to use for the SP-API endpoints.<br>Must be one of: eu , na or fe , use SpApiRegion.FarEast, SpApiRegion.NorthAmerica and SpApiRegion.Europe |
RefreshToken<br>optional | string | - | The refresh token of your app user.<br>Required if OnlyGrantlessOperations option is set to false . |
AccessToken<br>optional | string | - | The temporary access token requested with the refresh token of the app user. |
RoleCredentials<br>optional | object | - | The temporary role credentials for the sellingpartner api role of the iam user. Must include the three properties Id , Secret and SecurityToken with their corresponding values. You can get the by using RefreshRoleCredential() |
Credentials<br>optional | object | - | The app client and aws user credentials. Must include the five credentials properties SELLING_PARTNER_APP_CLIENT_ID , SELLING_PARTNER_APP_CLIENT_SECRET , AWS_ACCESS_KEY_ID , AWS_SECRET_ACCESS_KEY , AWS_SELLING_PARTNER_ROLE with their corresponding values.<br>NOTE: Should only be used if you have no means of using configuration vars or credentials file! |
Options<br>optional | object | - | Additional options, see table below for all possible options properties. |
Valid properties of the config options:
Name | Type | Default | Description |
---|---|---|---|
UseSandbox<br>optional | boolean | false | Whether or not to use the sandbox endpoint. |
OnlyGrantlessOperations<br>optional | boolean | false | Whether or not to only use grantless operations. |
OnlyGrantlessOperations<br>optional | boolean | false | Whether or not to use application configuration vars for credentials. |
Usage
Config api client
You have to provide these information.
var config = new Config()
{
Region = SpApiRegion.FarEast,
RefreshToken = "<SellerRefreshToken>",
Credentials = new Credentials()
{
AppClient = new AppClient()
{
Id = "<LWA client id>",
Secret = "<LWA client secret>",
},
AwsUser = new AwsUser()
{
Id = "<Aww User Id>",
SecretKey = "<Aws User Secret Key>",
Role = "<Aws User Role Arn>"
},
},
Options = new Options()
{
OnlyGrantlessOperations = false,
// if true, the endpoint will add sandbox prefix
UseSandbox = false
}
};
Refresh Access Token
If you don't have refresh token yet, you may specify the scope.
var config = new Config()
{
Region = SpApiRegion.FarEast,
...
};
var api = new SellingPartnerApi(config);
var refreshToken = api.RefreshAccessToken(SpApiScope.MIGRATION);
Refresh Access Token with Refresh Token
var config = new Config()
{
Region = SpApiRegion.FarEast,
RefreshToken = "<Refresh Token>"
...
};
var accessToken = api.RefreshAccessToken("");
Refresh User Role Credential
It will return RoleCredentials and save it to the client
var roleCredentials = api.RefreshRoleCredentials();
Call API
This project provide request Class for API so you could check those request Class see which part is required.
Order
Get Order
Endpoint: /orders/v0/orders/@orderId
Mehtod: GET
Request Class: GetOrderRequest
The endpoint with @orderId
means that is a path parameter. If you use
GetOrderPath
object for request, it will replace for you.
var request = new GetOrderRequest();
var path = new GetOrderPath();
path.OrderId = "<Order Id>";
request.Path = path;
var response = nonGrantlessApi.CallGetOrderApi(request);
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net472 is compatible. net48 was computed. net481 was computed. |
-
- Newtonsoft.Json (>= 13.0.1)
- RestSharp (>= 106.11.7)
- System.Numerics.Vectors (>= 4.5.0)
- System.Runtime.CompilerServices.Unsafe (>= 4.7.1)
- System.Text.Json (>= 4.7.2)
- System.Threading.Tasks.Extensions (>= 4.5.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Fix configuration file value key name