HomeDocumentationCode SamplesAPI ReferenceAnnouncementsModelsRelease NotesFAQGitHubVideos
Developer HubAPI StatusSupport
Documentation
Developer HubAPI StatusSupport

Generate a Java SDK

Generate a Java SDK with an LWA token exchange.

These instructions explain how to generate a Java SDK for the Sellers API using Swagger Code Generator on a computer running Microsoft Windows. The process is the same for users of other operating systems such as macOS or Linux, with the replacement of Windows-specific semantics (for example, C:\). Although these instructions are for the Sellers API, you can modify the instructions to generate SDKs for any other Selling Partner API. Refer to the Models page for Swagger models for each Selling Partner API section.

With this SDK you can make requests to the Selling Partner API with the following code, which is already set up for you: Login with Amazon (LWA) token exchange (exchange a refresh token for an access token).

To generate a Java SDK with LWA token exchange

  1. Install Java 8 or newer, Apache Maven 3.6. or greater, and GNU Wget and make them available in your $PATH.

  2. Go to the selling-partner-api-models repository on GitHub.

  3. Clone the repository to make a local copy on your computer, if you haven't done so already.

  4. Open a command prompt window and go to a directory where you want to download the Swagger Code Generator.

  5. Download the latest version of the Swagger Code Generator.

    For example:

    wget https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.13/swagger-codegen-cli-2.4.13.jar -O swagger-codegen-cli.jar
    

    swagger-codegen-cli.jar downloads to the current directory.

    📘

    Note

    You can also download from maven.org by directing your browser to https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.13/swagger-codegen-cli-2.4.13.jar

  6. Copy swagger-codegen-cli.jar into a directory structure that makes sense for you. For this example, we'll copy it to C:\SwaggerToCL.

  7. Navigate to sellers.json in the selling-partner-api-models\models\sellers-api-model folder of your local copy of the repository.

  8. Copy sellers.json into C:\SwaggerToCL.

  9. Generate the SDK against the templates in the selling-partner-api-models\clients\sellingpartner-api-aa-java folder of your local copy of the repository. This folder contains an authorization and authentication library, along with customized templates for the Swagger Code Generator and a config file to generate the correct version of the SDK.

    For example:

    java -jar C:\SwaggerToCL\swagger-codegen-cli.jar generate \
    -i C:\SwaggerToCL\Sellers.json \
    -l java \
    -t [path to selling-partner-api-models\clients\sellingpartner-api-aa-java folder]\resources\swagger-codegen\templates\ \
    -o C:\SwaggerToCL\Sellers_JavaCL \
    -c [path to selling-partner-api-models\clients\sellingpartner-api-aa-java folder]\resources\java\config.json
    

    The SDK is copied to C:\SwaggerToCL\Sellers_JavaCL

    📘

    Version notation:

    In the following steps, x.x refers to the latest version of the AA library. Refer to the readme for the latest version.

  10. Build the AA Library and add it as a dependency of the SDK:

    • Navigate to the selling-partner-api-models\clients\sellingpartner-api-aa-java folder of your local copy of the repository and run mvn package. This generates a folder named "target". In this folder is a JAR file named sellingpartnerapi-aa-java-x.x-jar-with-dependencies.jar (or something similar) and all of the required dependencies.

    • Install the JAR file in your local Maven repository.

      For example:

      mvn install:install-file -Dfile=[path to JAR file in "target" folder] -DgroupId=com.amazon.sellingpartnerapi -DartifactId=sellingpartnerapi-aa-java -Dversion=x.x -Dpackaging=jar
      

    You can find the actual groupId, artifactId, and version values near the top of the pom.xml file in the selling-partner-api-models\clients\sellingpartner-api-aa-java folder.

  11. Add a dependency on the AA library in the pom.xml of the client library:

    For example:

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

After you have generated your SDK you can use it to make calls to the Selling Partner API. Refer to Connecting to the Selling Partner API using a generated Java SDK.

📘

Logging request and response headers

To obtain request and response headers using your SDK, append WithHttpInfo to the method name. This new operation returns an ApiResponse<OperationNameResponse> object, which contains the header and status code in addition to the payload of the OperationName.

Example: The method getMarketplaceParticipations will return an object of type GetMarketplaceParticipationsResponse, whereas the operation getMarketplaceParticipationsWithHttpInfo will return an object of type ApiResponse<GetMarketplaceParticipationsResponse>. The ApiResponse<GetMarketplaceParticipationsResponse> object contains the header and status code as well as a GetMarketplaceParticipationsResponse object.