CardTraderAPI.Client
1.2.0
See the version list below for details.
dotnet add package CardTraderAPI.Client --version 1.2.0
NuGet\Install-Package CardTraderAPI.Client -Version 1.2.0
<PackageReference Include="CardTraderAPI.Client" Version="1.2.0" />
<PackageVersion Include="CardTraderAPI.Client" Version="1.2.0" />
<PackageReference Include="CardTraderAPI.Client" />
paket add CardTraderAPI.Client --version 1.2.0
#r "nuget: CardTraderAPI.Client, 1.2.0"
#:package CardTraderAPI.Client@1.2.0
#addin nuget:?package=CardTraderAPI.Client&version=1.2.0
#tool nuget:?package=CardTraderAPI.Client&version=1.2.0
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_idandquantity).
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
- Show
- Create
- Delete
Inventory Management
- List your Expansions
- List your Products
One Product Operations
- Create
- Update
- Delete
- Increment or Decrement
Batch Product Operations
- Create
- Update
- Delete
- Job
CSV Product Operations
- Upload
- Status
Order Management
- List your Orders
- Order Details
- Update
- 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 integration
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- Microsoft.Extensions.Caching.Memory (>= 9.0.2)
- Microsoft.Extensions.Http (>= 9.0.2)
- Polly (>= 8.5.2)
- System.Text.Json (>= 9.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.