Connecting to the Selling Partner API using a generated Java SDK

How to connect to the SP-API using a generated Java SDK.

Before your application can connect to the Selling Partner API, you must register it and it must be authorized by a selling partner. See Registering your application and Authorizing Selling Partner API applications.

These instructions show you how to use a generated Java SDK to make calls. The SDK exposes classes for configuring your LWA and AWS credentials and uses these to exchange LWA tokens and sign requests for you. For more information, see Generating a Java SDK with LWA token exchange and authentication.

Step 1. Configure your AWS credentials

Create an instance of AWSAuthenticationCredentials, using the following parameters:

NameDescriptionRequired
accessKeyIdYour AWS access key Id, from Step 2. Create an IAM user. Yes
secretKeyYour AWS secret access key, from Step 2. Create an IAM user. Yes
regionThe AWS region to which you are directing your call. For more information, see Selling Partner API endpoints.Yes

Example:

import com.amazon.SellingPartnerAPIAA.AWSAuthenticationCredentials;

AWSAuthenticationCredentials awsAuthenticationCredentials=AWSAuthenticationCredentials.builder()
  .accessKeyId("myAccessKeyId")
  .secretKey("mySecretId")
  .region("us-east-1")
  .build();

Step 2. Configure your AWS credentials provider

Create an instance of AWSAuthenticationCredentialsProvider, using the following parameters:

NameDescriptionRequired
roleArnThe ARN of the IAM role that you created in Step 4. Create an IAM role.Yes
roleSessionNameAn identifier for the session that you define. We recommend using a Universally Unique Identifier (UUID).Yes

Example:

import com.amazon.SellingPartnerAPIAA.AWSAuthenticationCredentialsProvider;

AWSAuthenticationCredentialsProvider awsAuthenticationCredentialsProvider=AWSAuthenticationCredentialsProvider.builder()
  .roleArn("myroleARN")
  .roleSessionName("myrolesessioname")
  .build();

Step 3. Configure your LWA credentials

Create an instance of LWAAuthorizationCredentials, using the following parameters:

NameDescriptionRequired
clientIdYour LWA client identifier. For more information, see Viewing your developer information.Yes
clientSecretYour LWA client secret. For more information, see Viewing your developer information.Yes
refreshTokenThe LWA refresh token. Get this value when the selling partner authorizes your application. For more information, see Authorizing Selling Partner API applications.

No. Include refreshToken if the operation that you call in the following step requires selling partner authorization. All operations that are not grantless operations require selling partner authorization. If you include refreshToken, do not include withScopes.

withScopes

The scope of the LWA authorization grant. You can specify one or more withScopes values.

Values:

  • SCOPE_NOTIFICATIONS_API. For the Notifications API.
  • SCOPE_MIGRATION_API. For the Authorization API.
No. Include withScopes if the operation that you call in the following step is a grantless operation. If you include withScopes, do not include refreshToken.
endpointThe LWA authentication server URI.Yes

Example for calling operations that require selling partner authorization:

import com.amazon.SellingPartnerAPIAA.LWAAuthorizationCredentials;

LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
  .clientId("myClientId")
  .clientSecret("myClientSecret")
  .refreshToken("Aztr|...")
  .endpoint("https://api.amazon.com/auth/o2/token")
  .build();

Example for calling grantless operations:

import com.amazon.SellingPartnerAPIAA.LWAAuthorizationCredentials;
import static com.amazon.SellingPartnerAPIAA.ScopeConstants.SCOPE_NOTIFICATIONS_API;
import static com.amazon.SellingPartnerAPIAA.ScopeConstants.SCOPE_MIGRATION_API;

LWAAuthorizationCredentials lwaAuthorizationCredentials =
  LWAAuthorizationCredentials.builder()
  .clientId("myClientId")
  .clientSecret("myClientSecret")
  .withScopes(SCOPE_NOTIFICATIONS_API, SCOPE_MIGRATION_API)
  .endpoint("https://api.amazon.com/auth/o2/token")
  .build();

Step 4. Create an instance of the Sellers API and call an operation

With your AWSAuthenticationCredentials, AWSAuthenticationCredentialsProvider, and LWAAuthorizationCredentials instances configured you can create an instance of SellersApi and call an operation.

Example:

SellersApi sellersApi = new SellersApi.Builder()
  .awsAuthenticationCredentials(awsAuthenticationCredentials)
  .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
  .awsAuthenticationCredentialsProvider(awsAuthenticationCredentialsProvider)
  .endpoint("https://sellingpartnerapi-na.amazon.com")
  .build();

Did this page help you?