SteamApi.Client
1.1.1
dotnet add package SteamApi.Client --version 1.1.1
NuGet\Install-Package SteamApi.Client -Version 1.1.1
<PackageReference Include="SteamApi.Client" Version="1.1.1" />
<PackageVersion Include="SteamApi.Client" Version="1.1.1" />
<PackageReference Include="SteamApi.Client" />
paket add SteamApi.Client --version 1.1.1
#r "nuget: SteamApi.Client, 1.1.1"
#:package SteamApi.Client@1.1.1
#addin nuget:?package=SteamApi.Client&version=1.1.1
#tool nuget:?package=SteamApi.Client&version=1.1.1
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:
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! });
Invalid API Key: Ensure the API key matches one of the valid keys configured in your Steam API service.
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" } }
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:
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 });
Verify the API key works in Swagger UI by entering it in the API key field.
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 errorsJsonException
- JSON deserialization errorsInvalidOperationException
- 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
Related Packages
- SteamApi.Models - Data transfer objects used by this client
- Steam API Service - The .NET service that this client connects to
- Docker Image - Docker container for the Steam API service
Source Code
- GitHub Repository - Main repository
License
MIT License - see 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.Configuration (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- SteamApi.Models (>= 1.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.