amzn / selling-partner-api-models

This repository contains OpenAPI models for developers to use when developing software to call Selling Partner APIs.
Apache License 2.0
611 stars 733 forks source link

Java SDK Generation - Documentation Unclear #1140

Closed FA5I closed 2 years ago

FA5I commented 3 years ago

I am playing around with the java library (I know how the auth flow works etc and have made a minimal python SDK that can make calls). However, I want to get familiar with the Amazon Java Client SDK, and I just cannot seem to figure out based on the documentation what to do next.

  1. I can successfully build and use the APIAA library detailed [here](package io.swagger.v3.oas.annotations.media does not exist) with my Maven project.
  2. Now, I want to access the SellersAPI and all of the classes and methods therein. I manage to successfully generate the models, and place them in a folder called "JavaCL":
Screenshot 2021-03-17 at 19 58 47

Within the model folder I have all of the models:

Screenshot 2021-03-17 at 19 59 12

My Kotlin code (which is completely interoperable with Java) looks as follows:

import com.amazon.SellingPartnerAPIAA.AWSAuthenticationCredentials;
import io.github.cdimascio.dotenv.dotenv
import com.amazon.SellingPartnerAPIAA.AWSAuthenticationCredentialsProvider
import com.amazon.SellingPartnerAPIAA.LWAAuthorizationCredentials;

val dotenv = dotenv();
val client_id = dotenv["client_id"]
val client_secret = dotenv["client_secret"]

fun main(args: Array<String>) {
    val awsAuthenticationCredentials = AWSAuthenticationCredentials.builder()
        .accessKeyId(dotenv["access_key_id"])
        .secretKey(dotenv["secret_access_key"])
        .region("us-east-1")
        .build()

    val awsAuthenticationCredentialsProvider = AWSAuthenticationCredentialsProvider.builder()
        .roleArn(dotenv["role_arn"])
        .roleSessionName("sp-api")
        .build()

    val lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
        .clientId(dotenv["client_id"])
        .clientSecret(dotenv["client_secret"])
        .refreshToken(dotenv["lwa_refresh_token"])
        .endpoint("https://api.amazon.com/auth/o2/token")
        .build()

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

}

As you can see below, in line 29 there is an unresolved reference (the APIAA stuff works fine). I do not understand why this is the case, since I have built the Jar as per the documentation, and also added it to my maven project as a dependency:

<dependency>
      <groupId>com.amazon.sellingpartnerapi</groupId>
      <artifactId>sellingpartnerapi-aa-java</artifactId>
      <version>1.0</version>
    </dependency>

Error:

Screenshot 2021-03-17 at 20 03 09

Can someone please help me out in trying to understand this? I would rather just use the Java SDK if it has all the endpoint calls and functions defined as per the open API schema.

parvathm commented 3 years ago

Hi @acse-fk4517,

Did you use Mustache templates while generating the Java client library? The Mustache templates that comes with Java AA library might not work with Open API generator.

Thanks, Parvathm, Selling Partner API Developer Support.

FA5I commented 3 years ago

Hi @parvathm ,

Yes I generate the SDK with the following flag:

--template-dir clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates

Does that mean I need to generate generate a separate Moustache template to get this to work?

The authentication Java AA works with no errors. I assumed this would mean it is working correctly with the Open API generator. To get the AA working I just followed the steps in the docs. However when I try and call the Seller API, the classes are not being picked up.

ashokrajab commented 3 years ago

@FA5I, did you try installing the generated SDK as mentioned in the ReadMe.md file?

Mentioning below the Installation steps found in ReadMe.md present in the generated SDK:

Installation

To install the API client library to your local Maven repository, simply execute:

mvn clean install

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

mvn clean deploy

Refer to the OSSRH Guide for more information.

Maven users

Add this dependency to your project's POM:

<dependency>
  <groupId>io.swagger</groupId>
  <artifactId>swagger-java-client</artifactId>
  <version>1.0.0</version>
  <scope>compile</scope>
</dependency>

Gradle users

Add this dependency to your project's build file:

compile "io.swagger:swagger-java-client:1.0.0"

Others

At first generate the JAR by executing:

mvn clean package

Then manually install the following JARs:

FA5I commented 3 years ago

Thanks @AshokRaja10 , I will take a look at this and implement the steps you have outlined!

MaximeMarcaisBoxtal commented 3 years ago

Hi!

I generated the Java SDK according to the doc (Generating a Java SDK with LWA token exchange and authentication). But my code doesn't compile when I try to implement a SellersApi, (Create an instance of the Sellers API and call an operation). The builder from SellersApi is not recognized. Here is my code:

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

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

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

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

What could I have missed? Thanks for your help!

litao1254 commented 3 years ago

The new API has no builder method, no awsauthenticationcredentials, lwaauthorizationcredentials, endpoint, lwaaccesstokencache, and so on

davidecampello commented 3 years ago

Same problem to me. It's not clear

github-actions[bot] commented 2 years ago

This is a very old issue that is probably not getting as much attention as it deserves. We encourage you to check if this is still an issue after the latest release and if you find that this is still a problem, please feel free to open a new issue and make a reference to this one.

abdallahaymaan commented 1 year ago

Same issue here (The SellerApi class isn't imported), anyone figured out a possible solution? I'm using a gradle project not maven so maybe I have missed out the installation part as its specified for maven only. Can anyone please specify how to install the library for a gradle repository.