HomeDocumentationCode SamplesAPI ReferenceAnnouncementsModelsRelease NotesFAQGitHubVideos
Developer HubAPI StatusSupport
Documentation
Developer HubAPI StatusSupport

Generate a C# SDK

Generate a C# SDK with LWA token generation and authentication.

This tutorial describes how to generate a C# Software Developer Kit (SDK) with Login with Amazon (LWA) token generation and authentication included. It uses the Sellers API as an example API and Microsoft Windows as the platform, but the steps can be modified for use with other APIs and platforms. Refer to SP-API models for Swagger models for each Selling Partner API section.

You can use this C# SDK to make requests to the Selling Partner API with LWA token generation (generate an access token using your refresh token) and authentication code already set up for you.

Step 1. Set up your workspace

  1. On your local drive, create a directory named SwaggerToCL.

  2. Download the software:

  3. Run this command to download the Swagger Code Generator:

    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
    
  4. Copy swagger-codegen-cli.jar into the C:\SwaggerToCL directory.

  5. From the command line, navigate to your local C:\SwaggerToCL directory and use this command to clone the selling-partner-api-models repository:

    git clone https://github.com/amzn/selling-partner-api-models
    
  6. Navigate to the selling-partner-api-models\models\sellers-api-model\sellers-api-model folder in your local copy of the repository.

  7. Copy the sellers.json file and paste it into C:\SwaggerToCL.

  8. Navigate to selling-partner-api-models/clients/sellingpartner-api-aa-csharp on GitHub and download the sellingpartner-api-aa-csharp folder to your local computer.

This folder provides helper classes to generate an access token and sign the requests for Amazon Selling Partner APIs. It is intended for use with the Selling Partner API client libraries generated by Swagger Codegen using the RestSharp library. It can also be integrated into custom projects.

Step 2. Generate a C# SDK with LWA token generation and authentication

  1. Open Visual Studio.
  2. In the sellingpartner-api-aa-csharp folder, select the SellingPartnerAPIAuthAndAuthCSharp.sln file and choose the build option in Visual Studio. This generates the Amazon.SellingPartnerAPIAA.dll assembly in the folder sellingpartner-api-aa-csharp\src\Amazon.SellingPartnerAPIAA\bin\Debug\netstandard2.0.
  3. Open a terminal and run the following commands to generate the C# client library. The default package name for the generated client library is Swagger.IO. These commands generate the client libraries with their respective API names as the package name instead of Swagger.IO.

In C:\SwaggerToCL, create a JSON file named csharpConfig.json. Open an editor and add this code. For packageName, use the same name as the API:

{"packageName":"SellingPartnerAPI.SellerAPI","targetFramework":"v4.7.2"}

Run this command to generate C# code with a customized package name:

java -jar C:\SwaggerToCL\swagger-codegen-cli.jar generate -i C:\SwaggerToCL\[name of model].json -l csharp -t [path to selling-partner-api-models\clients\sellingpartner-api-aa-csharp folder]\src\Amazon.SellingPartnerAPIAA\resources\swagger-codegen\templates\ -o C:\SwaggerToCL\[name of client library] -c C:\SwaggerToCL\csharpConfig.json

This command uses Sellers.json to generate C# code:

java -jar C:\SwaggerToCL\swagger-codegen-cli.jar generate -i C:\SwaggerToCL\Sellers.json -l csharp -t C:\SwaggerToCL\sellingpartner-api-aa-csharp\src\Amazon.SellingPartnerAPIAA\resources\swagger-codegen\templates\ -o C:\SwaggerToCL\Sellers_CsharpCL -c C:\SwaggerToCL\csharpConfig.json

The SDK is created in C:\SwaggerToCL\Sellers_CsharpCL. Now that you have generated your SDK, you can use it to make calls to the Selling Partner API. For additional instructions refer to Connect to the Selling Partner API using a generated C# SDK.