My code
AWSAuthenticationCredentials awsAuthenticationCredentials = AWSAuthenticationCredentials.builder()
.accessKeyId("XXXXXXXXXXXXXXX").secretKey("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
.region("eu-west-1").build();
AWSAuthenticationCredentialsProvider awsAuthenticationCredentialsProvider = AWSAuthenticationCredentialsProvider
.builder().roleArn("XXXXXXXXXXXXX").roleSessionName("123123123")
.build();
LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
.clientId("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
.clientSecret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
.endpoint("https://api.amazon.com/auth/o2/token").build();
SellersApi sellersApi = new SellersApi.Builder().awsAuthenticationCredentials(awsAuthenticationCredentials)
.lwaAuthorizationCredentials(lwaAuthorizationCredentials)
.awsAuthenticationCredentialsProvider(awsAuthenticationCredentialsProvider)
.endpoint("https://sellingpartnerapi-eu.amazon.com").build();
GetMarketplaceParticipationsResponse res = sellersApi.getMarketplaceParticipations();
List<MarketplaceParticipation> data = new ArrayList<MarketplaceParticipation>();
data = res.getPayload();
for (MarketplaceParticipation obj : data) {
System.out.println(obj);
}
Error:
Caused by: java.lang.RuntimeException: Error getting LWA Access Token at com.amazon.SellingPartnerAPIAA.LWAClient.getAccessTokenFromEndpoint(LWAClient.java:74) at com.amazon.SellingPartnerAPIAA.LWAClient.getAccessTokenFromCache(LWAClient.java:51) at com.amazon.SellingPartnerAPIAA.LWAClient.getAccessToken(LWAClient.java:40) at com.amazon.SellingPartnerAPIAA.LWAAuthorizationSigner.sign(LWAAuthorizationSigner.java:69) at com.amazon.sellingpartner.ApiClient.buildRequest(ApiClient.java:1034) at com.amazon.sellingpartner.ApiClient.buildCall(ApiClient.java:973) at com.amazon.sellingpartner.api.SellersApi.getMarketplaceParticipationsCall(SellersApi.java:111) at com.amazon.sellingpartner.api.SellersApi.getMarketplaceParticipationsValidateBeforeCall(SellersApi.java:118) at com.amazon.sellingpartner.api.SellersApi.getMarketplaceParticipationsWithHttpInfo(SellersApi.java:141) at com.amazon.sellingpartner.api.SellersApi.getMarketplaceParticipations(SellersApi.java:130) at com.yash.spapi.TestSpApiApplication.main(TestSpApiApplication.java:47) ... 5 more Caused by: java.io.IOException: Unsuccessful LWA token exchange at com.amazon.SellingPartnerAPIAA.LWAClient.getAccessTokenFromEndpoint(LWAClient.java:63) ... 15 more
You seem not to have provided the refresh token when constructing the
LWAAuthorizationCredentials
. Try inserting.refreshToken("<your-refresh-token>")
after.clientSecret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
.The following code works for me (with self authorization, and correct security parameters of course):