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:
Name | Description | Required |
---|---|---|
accessKeyId | Your AWS access key Id, from Step 2. Create an IAM user. | Yes |
secretKey | Your AWS secret access key, from Step 2. Create an IAM user. | Yes |
region | The 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();
2
3
4
5
6
7
# Step 2. Configure your AWS credentials provider
Create an instance of AWSAuthenticationCredentialsProvider
, using the following parameters:
Name | Description | Required |
---|---|---|
roleArn | The ARN of the IAM role that you created in Step 4. Create an IAM role. | Yes |
roleSessionName | An 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();
2
3
4
5
6
# Step 3. Configure your LWA credentials
Create an instance of LWAAuthorizationCredentials
, using the following parameters:
Name | Description | Required |
---|---|---|
clientId | Your LWA client identifier. For more information, see Viewing your developer information. | Yes |
clientSecret | Your LWA client secret. For more information, see Viewing your developer information. | Yes |
refreshToken | The 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:
| 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. |
endpoint | The 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();
2
3
4
5
6
7
8
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();
2
3
4
5
6
7
8
9
10
11
# 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();
2
3
4
5
6