CardTraderAPI.Client 1.3.0

dotnet add package CardTraderAPI.Client --version 1.3.0
                    
NuGet\Install-Package CardTraderAPI.Client -Version 1.3.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CardTraderAPI.Client" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CardTraderAPI.Client" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="CardTraderAPI.Client" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CardTraderAPI.Client --version 1.3.0
                    
#r "nuget: CardTraderAPI.Client, 1.3.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CardTraderAPI.Client@1.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CardTraderAPI.Client&version=1.3.0
                    
Install as a Cake Addin
#tool nuget:?package=CardTraderAPI.Client&version=1.3.0
                    
Install as a Cake Tool

CardTraderAPI .NET Client Library

The CardTraderAPI is a .NET library designed for seamless interactions with the CardTrader API. It simplifies API calls, manages the HTTP client, supports custom request bodies, and integrates Dependency Injection for use in .NET applications.

Disclaimer

This project is not affiliated with cardtrader.com in any way. It is an unofficial library created to help developers integrate with CardTrader APIs.

Features

  • Simplified HTTP client for API calls.
  • Support for creating, updating, and deleting products in the inventory.
  • Handling of marketplace items and user cart management.
  • Easy integration with Dependency Injection.
  • Supports serializing custom bodies (e.g., product_id and quantity).

Installation

To install the CardTraderAPI NuGet package, run the following command in your project:

.NET CLI

dotnet add package CardTraderAPI.Client

Package Manager

NuGet\Install-Package CardTraderAPI.Client

Alternatively, you can use the NuGet Package Manager in Visual Studio to search for CardTraderAPI.Client and install it.

Usage

1. Setup Dependency Injection and JWT Token

In your Program.cs, you need to configure Dependency Injection and provide your JWT token.

    using CardTraderApi.Client;
    using Microsoft.Extensions.DependencyInjection;

    namespace ConsoleAppTest
    {
        class Program
        {
            private const string JwtToken = "INSERT_HERE_JWTTOKEN";

            static async Task Main()
            {
                // Create a new service collection
                var services = new ServiceCollection();

                // Register the CardTrader API client with Dependency Injection and JWT token
                services.AddCardTraderApiClient(JwtToken);

                // Build the service provider
                var serviceProvider = services.BuildServiceProvider();

                // Retrieve the API client from the DI container
                var cardTraderApiClient = serviceProvider.GetRequiredService<CardTraderApiClient>();

                // Use the API client to interact with the CardTrader API
                await PerformInventoryOperations(cardTraderApiClient);
            }

            static async Task PerformInventoryOperations(CardTraderApiClient cardTraderApiClient)
            {
                // Example: Get all user products
                var products = await cardTraderApiClient.Inventory.GetUserProducts();
                Console.WriteLine($"Found {products.Count} products.");

                // Example: Add a new product
                var createResponse = await cardTraderApiClient.Inventory.Create(16, 5000.00m, 1);
                Console.WriteLine($"Product created with ID: {createResponse.Resource.Id}");

                // Example: Remove a product
                var deleteResponse = await cardTraderApiClient.Inventory.Delete(createResponse.Resource.Id);
                Console.WriteLine($"Product deleted with ID: {createResponse.Resource.Id}");
            }
        }
    }

2. Interact with Inventory

You can use the following methods to interact with the inventory:

  • Get all user products:
      var products = await cardTraderApiClient.Inventory.GetUserProducts();
  • Add a new product:
      var createResponse = await cardTraderApiClient.Inventory.Create(16, 5000.00m, 1);
  • Remove a product:
      var deleteResponse = await cardTraderApiClient.Inventory.Delete(productId);

3. Interact with Marketplace

You can also interact with the marketplace, such as retrieving items or adding/removing products from the user's cart:

  • Get marketplace items by blueprint ID:
      var marketplaceItems = await cardTraderApiClient.Marketplace.GetMarketPlaceProductByBlueprintId(38955);
  • Add a product to the user's cart:
      var cartUpdated = await cardTraderApiClient.Marketplace.AddProduct(285708175, 1, true);
  • Remove a product from the user's cart:
      var cartRemoveUpdated = await cardTraderApiClient.Marketplace.RemoveProduct(285708175, 1);

4. Handling Errors

If an error occurs during an API request, you can catch it like this:

    try
    {
        var marketplaceItems = await cardTraderApiClient.Marketplace.GetMarketPlaceProductByBlueprintId(38955);
    }
    catch (CardTraderApiException ex)
    {
        Console.WriteLine($"CardTrader API Exception: {ex.Message}");
        Console.WriteLine($"Status Code: {ex.ResponseStatusCode}");
        Console.WriteLine($"Request URI: {ex.RequestUri}");
        Console.WriteLine($"Request Method: {ex.RequestMethod}");
        throw;
    }

Roadmap

Below is an overview of existing features (marked with [x]) and planned features (marked with [ ]):

Marketplace

  • List Marketplace Products
  • Cart Status
  • Add Product to Cart
  • Remove Product from Cart
  • Purchase
  • Shipping Methods

Wishlists

  • List
  • Show
  • Create
  • Delete

Inventory Management

  • List your Expansions
  • List your Products

One Product Operations

  • Create
  • Update
  • Delete
  • Increment or Decrement
  • Add Image
  • Remove Image

Batch Product Operations

  • Create
  • Update
  • Delete
  • Job

CSV Product Operations

  • Upload
  • Status

Order Management

  • List your Orders
  • Order Details
  • Set Tracking Code
  • Ship
  • Request Cancellation
  • Confirm Cancellation

CT0 Box Items

  • List your CT0 Box Items
  • CT0 Box Item Details

Errors

  • Exceptions handled via CardTraderApiException

Webhooks

  • Webhook signature verification via WebhookValidator

Contributing

Feel free to submit issues, fork the repository, and send pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.0 702 3/24/2026
1.2.0 198 10/1/2025
1.1.5 296 5/15/2025
1.1.4 291 5/12/2025
1.1.0 231 4/11/2025
1.0.9 669 4/10/2025 1.0.9 is deprecated because it is no longer maintained.
1.0.8 317 4/10/2025 1.0.8 is deprecated because it is no longer maintained.
1.0.7 338 4/7/2025 1.0.7 is deprecated because it is no longer maintained.
1.0.6 281 2/25/2025 1.0.6 is deprecated because it is no longer maintained.