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. Please refer to 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 Login with Amazon (LWA) credentials and use them to generate LWA tokens and sign requests for you. For more information, see Generating a Java SDK with LWA token exchange.
Step 1. 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. Takes the value `ScopeNotificationsAPI` for the Notifications 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. |
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();
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 2. Create an instance of the Sellers API and call an operation
With your LWAAuthorizationCredentials
instances configured you can create an instance of SellersApi and call an operation.
Example:
SellersApi sellersApi = new SellersApi.Builder()
.lwaAuthorizationCredentials(lwaAuthorizationCredentials)
.endpoint("https://sellingpartnerapi-na.amazon.com")
.build();
Updated 5 months ago