Skip to content

TCG-Price-Lookup/tcg-api-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tcg-api-examples

License: MIT Powered by TCG Price Lookup

Working code examples for the TCG Price Lookup API in 8 languages — JavaScript, Python, Go, Rust, PHP, Ruby, Java, and C#.

One API for every major trading card game. Pokemon, Magic: The Gathering, Yu-Gi-Oh!, Disney Lorcana, One Piece TCG, Star Wars: Unlimited, and Flesh and Blood — all from a single REST endpoint with TCGPlayer market prices, eBay sold averages, and PSA / BGS / CGC graded comps.

Each example is runnable, self-contained, and uses idiomatic patterns for its language. Where an official SDK exists, the example uses it. Where no SDK is published yet, the example uses the language's standard library HTTP client — no third-party dependencies required.

Get an API key

Sign up free at tcgpricelookup.com/tcg-api. The free tier gives you 10,000 requests per month with TCGPlayer market prices. Trader plan and above unlocks eBay sold averages, full graded prices, and price history.

Examples

Language Example SDK Notes
JavaScript / TypeScript node search.js @tcgpricelookup/sdk ESM, async/await
Python python search.py tcglookup Python 3.9+, sync, context manager
Go go run main.go tcglookup-go Functional options, typed errors
Rust cargo run tcglookup Async with tokio
PHP php search.php tcgpricelookup/sdk PHP 8.1+, Composer, Guzzle
Ruby ruby search.rb stdlib net/http Zero gems, single file
Java java Search.java stdlib HttpClient JDK 11+, single-file launcher
C# dotnet run stdlib HttpClient .NET 6+, no NuGet packages

What every example does

All 8 examples cover the same three operations so you can compare them side by side:

  1. Searchcards.search with query, game filter, and limit
  2. Get onecards.get to fetch the full price block for a single card
  3. Read rate-limit headers — every example reads the rate-limit window after the call

Each also includes typed error handling for the most common failure modes:

  • PlanAccess (HTTP 403) — your plan does not include this resource (e.g. price history on Free)
  • RateLimit (HTTP 429) — quota exceeded for the current window

Quickstart in any language

JavaScript / TypeScript

import { TcgLookupClient } from "@tcgpricelookup/sdk";

const client = new TcgLookupClient({ apiKey: process.env.TCGLOOKUP_API_KEY });
const results = await client.cards.search({ q: "charizard", game: "pokemon", limit: 5 });

Python

from tcglookup import TcgLookupClient

client = TcgLookupClient(api_key=os.environ["TCGLOOKUP_API_KEY"])
results = client.cards.search(q="charizard", game="pokemon", limit=5)

Go

import "github.com/TCG-Price-Lookup/tcglookup-go/tcglookup"

client := tcglookup.NewClient(os.Getenv("TCGLOOKUP_API_KEY"))
results, _ := client.Cards.Search(ctx, &tcglookup.CardSearchParams{
    Q: "charizard", Game: "pokemon", Limit: 5,
})

Rust

use tcglookup::{Client, CardSearchParams};

let client = Client::new(std::env::var("TCGLOOKUP_API_KEY")?);
let results = client.cards().search(CardSearchParams {
    q: Some("charizard".into()),
    game: Some("pokemon".into()),
    limit: Some(5),
    ..Default::default()
}).await?;

PHP

use TcgPriceLookup\Client;

$client = new Client(getenv('TCGLOOKUP_API_KEY'));
$results = $client->cards->search(['q' => 'charizard', 'game' => 'pokemon', 'limit' => 5]);

Ruby

require_relative 'search'  # see ruby/search.rb

client = TcgLookupClient.new(ENV['TCGLOOKUP_API_KEY'])
results = client.get('/cards/search', q: 'charizard', game: 'pokemon', limit: 5)

Java

TcgLookupClient client = new TcgLookupClient(System.getenv("TCGLOOKUP_API_KEY"));
Map<String, Object> results = client.get("/cards/search",
    Map.of("q", "charizard", "game", "pokemon", "limit", "5"));

C#

var client = new TcgLookupClient(Environment.GetEnvironmentVariable("TCGLOOKUP_API_KEY")!);
var results = await client.GetAsync("/cards/search", new()
{
    ["q"] = "charizard",
    ["game"] = "pokemon",
    ["limit"] = "5",
});

Supported games

The TCG Price Lookup API covers every major trading card game. Use these slugs in the game parameter of any call:

Slug Game
pokemon Pokemon TCG (English)
pokemon-jp Pokemon TCG (Japanese)
mtg Magic: The Gathering
yugioh Yu-Gi-Oh!
lorcana Disney Lorcana
onepiece One Piece TCG
swu Star Wars: Unlimited
fab Flesh and Blood

API endpoints

Endpoint Description Plan
GET /v1/cards/search Search cards by name, set, game, or batch IDs Free
GET /v1/cards/{id} Fetch a single card with full price block Free
GET /v1/cards/{id}/history Daily price history (7d / 30d / 90d / 1y) Trader
GET /v1/sets List sets, optionally filtered by game Free
GET /v1/games List every supported game with catalog size Free

Auth via X-API-Key header. Full API reference at tcgpricelookup.com/docs/api-reference.

Want a SDK in your language?

If you want a published native SDK for Ruby, Java, C#, or any other language, open an issue on the awesome-tcg repo. The HTTP layer is small enough that the examples in this repo are usable as-is for production code in the meantime.

Related repos

License

MIT — see LICENSE.


Built and maintained by TCG Price Lookup. Get a free API key at tcgpricelookup.com/tcg-api.

Releases

No releases published

Packages

 
 
 

Contributors