AmzSpApi 0.0.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package AmzSpApi --version 0.0.5                
NuGet\Install-Package AmzSpApi -Version 0.0.5                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AmzSpApi" Version="0.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AmzSpApi --version 0.0.5                
#r "nuget: AmzSpApi, 0.0.5"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AmzSpApi as a Cake Addin
#addin nuget:?package=AmzSpApi&version=0.0.5

// Install AmzSpApi as a Cake Tool
#tool nuget:?package=AmzSpApi&version=0.0.5                

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

Add these setting in configuration file.

  • <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.
UseConfigurationCredential<br>optional boolean false Whether or not to use application configuration vars for credentials.
AutoRequestTokens<br>optional boolean true Whether or not to get access token automatically.
AutoRequestThrottled<br>optional boolean true Whether or not to wait when API request exceed quota.

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
                }
            };

Get access token yourself

You can set Options property AutoRequestTokens as false and get Access Token and Security Token by your self. If AutoRequestTokens is true, SellingPartnerApi will get access token and security token when users do not assign or expired.

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

MIT

Product Compatible and additional computed target framework versions.
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.11 647 8/19/2021
0.0.10 343 8/18/2021
0.0.9 335 8/18/2021
0.0.8 333 8/16/2021
0.0.7 357 8/6/2021
0.0.6 396 8/5/2021
0.0.5 367 8/2/2021
0.0.4 411 7/26/2021
0.0.3 348 7/19/2021
0.0.2 493 7/16/2021

Add Authorization API, auto refresh token and auto throttling response.