Examples
Drop-in recipes for common integrations: inventory sync, product pages, carts, and collection trackers.
Price sync for inventory
Fetch every card in a set, automatically paginating until done.
price-sync.js
// Price sync for inventory: fetch every card in a set, paginated.
const API_KEY = 'tcg_your_api_key_here';
const BASE_URL = 'https://api.justtcg.com/v1';
async function updatePricesForSet(gameId, setId) {
let allCards = [];
let offset = 0;
const LIMIT = 20;
let hasMore = true;
while (hasMore) {
const url = new URL(`${BASE_URL}/cards`);
url.searchParams.set('game', gameId);
url.searchParams.set('set', setId);
url.searchParams.set('limit', String(LIMIT));
url.searchParams.set('offset', String(offset));
const res = await fetch(url, { headers: { 'x-api-key': API_KEY } });
const json = await res.json();
if (!res.ok) throw new Error(json.error ?? 'Request failed');
allCards = allCards.concat(json.data);
hasMore = json.data.length === LIMIT;
offset += LIMIT;
}
return allCards;
}
updatePricesForSet('magic-the-gathering', 'modern-horizons-2-magic-the-gathering');Product page display
Batch-fetch multiple cards for a product page in a single request.
product-page.js
// Product page: batch lookup by tcgplayerId.
const res = await fetch('https://api.justtcg.com/v1/cards', {
method: 'POST',
headers: {
'x-api-key': 'tcg_your_api_key_here',
'Content-Type': 'application/json',
},
body: JSON.stringify(
['219042', '25788', '1369'].map((id) => ({ tcgplayerId: id }))
),
});
const { data } = await res.json();
data.forEach((card) => {
const lowest = Math.min(...card.variants.map((v) => v.price));
console.log(`${card.name} — from $${lowest.toFixed(2)}`);
});Shopping cart calculation
Get current prices for specific variants in a cart and sum the total.
cart.js
// Shopping cart: get up-to-date prices for specific variants.
const cart = [
{ tcgplayerId: '219042', condition: 'Near Mint', printing: 'Normal' },
{ tcgplayerId: '25788', condition: 'Lightly Played', printing: '1st Edition' },
];
const res = await fetch('https://api.justtcg.com/v1/cards', {
method: 'POST',
headers: {
'x-api-key': 'tcg_your_api_key_here',
'Content-Type': 'application/json',
},
body: JSON.stringify(cart),
});
const { data } = await res.json();
const total = data.reduce((sum, c) => sum + c.variants[0].price, 0);
console.log(`Cart total: $${total.toFixed(2)}`);Collection price tracker (Python)
Track current market prices for a personal collection in Python.
collection.py
# Collection price tracker.
import os, requests
API_KEY = os.environ["JUSTTCG_API_KEY"]
BASE_URL = "https://api.justtcg.com/v1"
collection = [
{"tcgplayerId": "219042", "condition": "Near Mint", "printing": "Normal"},
{"tcgplayerId": "25788", "condition": "Lightly Played", "printing": "1st Edition"},
]
resp = requests.post(
f"{BASE_URL}/cards",
headers={"x-api-key": API_KEY, "Content-Type": "application/json"},
json=collection,
)
resp.raise_for_status()
for item in resp.json()["data"]:
v = item["variants"][0]
print(f"{item['name']} ({v['condition']}, {v['printing']}): ${v['price']:.2f}")