SteamApi.Client 1.1.1

dotnet add package SteamApi.Client --version 1.1.1
                    
NuGet\Install-Package SteamApi.Client -Version 1.1.1
                    
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="SteamApi.Client" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SteamApi.Client" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="SteamApi.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 SteamApi.Client --version 1.1.1
                    
#r "nuget: SteamApi.Client, 1.1.1"
                    
#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 SteamApi.Client@1.1.1
                    
#: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=SteamApi.Client&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=SteamApi.Client&version=1.1.1
                    
Install as a Cake Tool

SteamApi.Client

Client library for Steam API .NET service.

Overview

This package provides a strongly-typed HTTP client for interacting with the Steam API .NET service. It includes:

  • Type-safe API calls - All methods return strongly-typed models from SteamApi.Models
  • Dependency injection support - Easy integration with .NET applications
  • Configurable options - Customize base URL, timeouts, API keys, and more
  • Logging support - Built-in request/response logging
  • Cancellation support - All methods support cancellation tokens
  • Docker support - Works with the Docker container

Installation

dotnet add package SteamApi.Client

Quick Start

Basic Usage

using SteamApi.Client;
using SteamApi.Client.Extensions;

// Register the client
services.AddSteamApiClient(options =>
{
    options.BaseUrl = "https://your-steam-api.com";
    options.ApiKey = "your-api-key";
});

// Use the client
public class MyService
{
    private readonly ISteamApiClient _steamClient;

    public MyService(ISteamApiClient steamClient)
    {
        _steamClient = steamClient;
    }

    public async Task GetPlayerInfo()
    {
        var playerSummaries = await _steamClient.GetPlayerSummariesAsync("76561198000000000");
        var player = playerSummaries.Response?.Players.FirstOrDefault();
        
        Console.WriteLine($"Player: {player?.PersonaName}");
    }
}

Resolving Steam Vanity URLs

The client can resolve Steam vanity URLs to Steam IDs, accepting either the vanity URL directly or a full Steam Community URL:

// Resolve using just the vanity URL
var result1 = await _steamClient.ResolveVanityUrlAsync("pickleman");
Console.WriteLine($"Steam ID: {result1.Response?.SteamId}");

// Resolve using a full Steam Community URL
var result2 = await _steamClient.ResolveVanityUrlAsync("https://steamcommunity.com/id/pickleman");
Console.WriteLine($"Steam ID: {result2.Response?.SteamId}");

// Resolve a Steam group (urlType = 2)
var groupResult = await _steamClient.ResolveVanityUrlAsync("valve", urlType: 2);
Console.WriteLine($"Group ID: {groupResult.Response?.SteamId}");

Complete Example

Here's a complete example showing how to resolve a Steam vanity URL and then get player information:

using SteamApi.Client;
using SteamApi.Client.Extensions;

// Setup
var services = new ServiceCollection();
services.AddSteamApiClient(options =>
{
    options.BaseUrl = "https://your-steam-api.com";
    options.ApiKey = "your-api-key";
});

var serviceProvider = services.BuildServiceProvider();
var steamClient = serviceProvider.GetRequiredService<ISteamApiClient>();

// Resolve vanity URL to Steam ID
var vanityResult = await steamClient.ResolveVanityUrlAsync("ac89");
if (vanityResult.Response?.Success == 1)
{
    var steamId = vanityResult.Response.SteamId;
    Console.WriteLine($"Resolved Steam ID: {steamId}");
    
    // Get player information using the resolved Steam ID
    var playerInfo = await steamClient.GetPlayerSummariesAsync(steamId);
    var player = playerInfo.Response?.Players.FirstOrDefault();
    
    if (player != null)
    {
        Console.WriteLine($"Player Name: {player.PersonaName}");
        Console.WriteLine($"Profile URL: {player.ProfileUrl}");
        Console.WriteLine($"Avatar: {player.Avatar}");
    }
}
else
{
    Console.WriteLine($"Failed to resolve vanity URL: {vanityResult.Response?.Message}");
}

Using with Docker

If you're running the Steam API service in Docker:

services.AddSteamApiClient(options =>
{
    options.BaseUrl = "http://localhost:5000"; // Docker container port
    options.ApiKey = "your-api-key";
});
# Run the Docker container
docker run -p 5000:80 -e "SteamApi__ApiKey=your-api-key" lilchim/steam-api-dotnet:latest

Configuration from appsettings.json

{
  "SteamApiClient": {
    "BaseUrl": "https://your-steam-api.com",
    "ApiKey": "your-api-key",
    "TimeoutSeconds": 30,
    "EnableLogging": true
  }
}
// Register with configuration
services.AddSteamApiClient(configuration);

Troubleshooting

403 Forbidden Errors

If you're getting 403 Forbidden errors from the API, it's likely due to missing or invalid API key authentication. The Steam API service requires a valid API key to be sent in the X-API-Key header.

Common issues:

  1. Missing API Key: Make sure you've configured the ApiKey property in your client options:

    services.AddSteamApiClient(options =>
    {
        options.BaseUrl = "https://your-steam-api.com";
        options.ApiKey = "your-actual-api-key"; // This is required!
    });
    
  2. Invalid API Key: Ensure the API key matches one of the valid keys configured in your Steam API service.

  3. Configuration Issues: If using configuration from appsettings.json, verify the API key is properly set:

    {
      "SteamApiClient": {
        "BaseUrl": "https://your-steam-api.com",
        "ApiKey": "your-actual-api-key"
      }
    }
    
  4. Environment Variables: When using Docker, ensure the API key environment variable is set:

    docker run -p 5000:80 -e "SteamApi__ApiKey=your-actual-api-key" lilchim/steam-api-dotnet:latest
    

Verification Steps:

  1. Check that your API key is being sent by enabling logging:

    services.AddSteamApiClient(options =>
    {
        options.BaseUrl = "https://your-steam-api.com";
        options.ApiKey = "your-api-key";
        options.EnableLogging = true; // This will log requests
    });
    
  2. Verify the API key works in Swagger UI by entering it in the API key field.

  3. Test with a simple HTTP client to confirm the API key is valid:

    curl -H "X-API-Key: your-api-key" https://your-steam-api.com/api/status
    

API Methods

Player Information

// Get player summaries
var summaries = await client.GetPlayerSummariesAsync("76561198000000000,76561198000000001");

// Get friend list
var friends = await client.GetFriendListAsync("76561198000000000");

// Get player bans
var bans = await client.GetPlayerBansAsync("76561198000000000");

Game Information

// Get owned games
var ownedGames = await client.GetOwnedGamesAsync("76561198000000000", includeAppInfo: true);

// Get recently played games
var recentGames = await client.GetRecentlyPlayedGamesAsync("76561198000000000", count: 10);

// Get game news
var news = await client.GetNewsForAppAsync(730, count: 5); // Counter-Strike 2
var newsItem = news.Response?.AppNews.NewsItems.FirstOrDefault();
Console.WriteLine($"News: {newsItem?.Title}");

// Get achievement percentages
var achievements = await client.GetGlobalAchievementPercentagesForAppAsync(730);

// Get player achievements for a specific game
var playerAchievements = await client.GetPlayerAchievementsAsync("76561198000000000", 238960); // Path of Exile
var achievement = playerAchievements.Response?.PlayerStats.Achievements.FirstOrDefault();
Console.WriteLine($"Achievement: {achievement?.ApiName}, Achieved: {achievement?.Achieved == 1}");

// Get app list
var apps = await client.GetAppListAsync();

Store Information

// Get store details for a single app
var appDetails = await client.GetStoreAppDetailsAsync(238960); // Path of Exile

// Get store details for multiple apps
var multipleAppDetails = await client.GetStoreAppDetailsMultipleAsync("238960,730,440"); // Path of Exile, CS2, TF2

// Access store information
var app = appDetails["238960"];
Console.WriteLine($"App: {app.Data?.Name}");
Console.WriteLine($"Type: {app.Data?.Type}");
Console.WriteLine($"Is Free: {app.Data?.IsFree}");
Console.WriteLine($"Developers: {string.Join(", ", app.Data?.Developers ?? new List<string>())}");

Status

// Get API status
var status = await client.GetStatusAsync();
Console.WriteLine($"API Status: {status.Status}");

Configuration Options

SteamApiClientOptions

Property Type Default Description
BaseUrl string "http://localhost:5000" Base URL of the Steam API service
ApiKey string? null API key for authentication
TimeoutSeconds int 30 HTTP request timeout in seconds
MaxRetries int 3 Maximum number of retry attempts (planned for future releases)
EnableLogging bool false Whether to enable request/response logging
UserAgent string "SteamApi.Client/1.0.1" User agent string for HTTP requests
Cache CacheOptions new() Cache configuration

CacheOptions

Property Type Default Description
Enabled bool false Whether caching is enabled
Type CacheType Memory Cache type to use
DefaultTtlMinutes int 15 Default time-to-live for cached items
RedisConnectionString string? null Redis connection string

Note: Caching functionality is planned for future releases. The cache options are currently available for configuration but not yet implemented.

Error Handling

The client throws standard .NET exceptions:

  • HttpRequestException - Network or HTTP errors
  • JsonException - JSON deserialization errors
  • InvalidOperationException - Configuration or deserialization errors
try
{
    var result = await client.GetPlayerSummariesAsync("76561198000000000");
}
catch (HttpRequestException ex)
{
    Console.WriteLine($"HTTP error: {ex.Message}");
}
catch (JsonException ex)
{
    Console.WriteLine($"JSON error: {ex.Message}");
}

Logging

Enable request/response logging:

services.AddSteamApiClient(options =>
{
    options.BaseUrl = "https://your-steam-api.com";
    options.EnableLogging = true;
});

Dependencies

  • SteamApi.Models - Data transfer objects
  • Microsoft.Extensions.Http - HTTP client factory
  • Microsoft.Extensions.Options - Configuration options
  • Microsoft.Extensions.Logging.Abstractions - Logging support
  • Microsoft.Extensions.Configuration - Configuration binding
  • Microsoft.Extensions.Configuration.Binder - Configuration binding support

Source Code

License

MIT License - see LICENSE file for details.

Product 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. 
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.1.1 163 8/7/2025
1.1.0 164 8/6/2025
1.0.6 14 8/2/2025
1.0.5 87 7/31/2025
1.0.4 86 7/31/2025
1.0.3 132 7/15/2025
1.0.1 113 7/15/2025
1.0.0 112 7/15/2025