Skip to content

Practical Examples

TeemoCell edited this page Jul 20, 2026 · 3 revisions

Practical Examples

All examples assume a configured root client:

use TeemoCell\SteamWebApi\Client;

$steam = new Client(apiKey: $_ENV['STEAM_API_KEY']);

Display a profile

$players = $steam->user($steamId)->GetPlayerSummaries();
$player = $players[0] ?? null;

if ($player !== null) {
    echo $player->personaName;
}

Load owned games

$games = $steam->player($steamId)->GetOwnedGames(
    includeAppInfo: true,
);

$mostPlayed = $games->sortByDesc('playtimeForever')->first();

Load achievements

$achievements = $steam
    ->userStats($steamId)
    ->GetPlayerAchievements($appId);

$unlocked = array_filter(
    $achievements ?? [],
    static fn ($achievement) => $achievement->achieved,
);

Read current players

$currentPlayers = $steam
    ->userStats()
    ->GetNumberOfCurrentPlayers(620);

Search Workshop files

$response = $steam->workshop()->QueryFiles([
    'query_type' => 1,
    'appid' => 620,
    'numperpage' => 20,
    'return_details' => true,
    'return_tags' => true,
]);

Load a public Community inventory

$inventory = $steam->communityInventory()->GetInventory(
    steamId: $steamId,
    appId: 730,
    contextId: 2,
    language: 'english',
);

foreach ($inventory->items as $item) {
    echo $item->name.PHP_EOL;
    echo $item->iconUrl.PHP_EOL;
}

The Community inventory client follows all pages automatically. It exposes marketHashName for market-aware applications but does not query or calculate Community Market resale prices.

Resolve a vanity name

$result = $steam
    ->user(76561197960287930)
    ->ResolveVanityURL('example-name');

$resolvedSteamId = $result->response->steamid ?? null;

Laravel caching

use Illuminate\Support\Facades\Cache;

$player = Cache::remember(
    "steam:player:{$steamId}",
    now()->addMinutes(5),
    fn () => $steam->user($steamId)->GetPlayerSummaries()[0] ?? null,
);

See Rate limits and caching and Error handling before using live calls in request-critical paths.

Clone this wiki locally