What does the bot do?
A member types /price card:charizard ex game:pokemon and the bot replies with the card's image, its current price, the market that price came from and when it was observed. That is two calls to the Flipzi Data API and about sixty lines of discord.js. The same pattern works for a Telegram or Slack bot; only the reply format changes.
You need Node 18 or newer, a Discord application with a bot token, and a Data API key. Create a free developer account to get one.
1. The two API calls
Search returns candidates; the price call takes the chosen id.
curl --fail-with-body --get 'https://data.flipzi.io/v1/cards/search' \
--data-urlencode 'q=charizard ex' \
--data-urlencode 'game=pokemon' \
--data-urlencode 'page_size=5' \
-H "X-API-Key: $FLIPZI_KEY"
curl --fail-with-body \
'https://data.flipzi.io/v1/cards/0908653a-ce24-4d7e-811e-78c2935bd822/price?currency=eur' \
-H "X-API-Key: $FLIPZI_KEY"
A search result carries id, name, set, number, rarity and image_url. A price row carries price_cents, price_formatted, market, confidence and updated_at. Run both in the playground to see full responses.
2. Register the slash command
Run this once. It registers /price with a card name, an optional game and an optional set code and number for members who want one exact card.
// register.js (npm install discord.js)
import { REST, Routes, SlashCommandBuilder } from 'discord.js';
const command = new SlashCommandBuilder()
.setName('price')
.setDescription('Current price of a trading card')
.addStringOption(o => o.setName('card').setDescription('Card name').setRequired(true))
.addStringOption(o => o.setName('game').setDescription('Game').addChoices(
{ name: 'Pokémon', value: 'pokemon' },
{ name: 'Pokémon (Japanese)', value: 'pokemon-jp' },
{ name: 'One Piece', value: 'onepiece' },
{ name: 'Magic', value: 'mtg' },
{ name: 'Yu-Gi-Oh!', value: 'yugioh' },
{ name: 'Lorcana', value: 'lorcana' },
))
.addStringOption(o => o.setName('number').setDescription('Collector number, e.g. 125'));
const rest = new REST().setToken(process.env.DISCORD_TOKEN);
await rest.put(Routes.applicationCommands(process.env.DISCORD_APP_ID), { body: [command.toJSON()] });
console.log('Registered /price');
The game ids are the ones GET /v1/catalog/games returns; add the others your community plays.
3. Answer it
// bot.js
import { Client, EmbedBuilder, Events, GatewayIntentBits } from 'discord.js';
const API = 'https://data.flipzi.io';
const HEADERS = { 'X-API-Key': process.env.FLIPZI_KEY };
const cache = new Map(); // url -> { at, body }
const TTL_MS = 10 * 60 * 1000;
async function flipzi(path, params = {}) {
const url = `${API}${path}?${new URLSearchParams(params)}`;
const hit = cache.get(url);
if (hit && Date.now() - hit.at < TTL_MS) return hit.body;
const res = await fetch(url, { headers: HEADERS });
if (res.status === 429) throw new Error('Busy, try again in a minute.');
if (!res.ok) throw new Error(`Price service answered ${res.status}.`);
const body = await res.json();
cache.set(url, { at: Date.now(), body });
return body;
}
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand() || interaction.commandName !== 'price') return;
await interaction.deferReply(); // the API calls may take longer than 3 s
try {
const params = { q: interaction.options.getString('card'), page_size: 1 };
const game = interaction.options.getString('game') ?? 'pokemon';
const number = interaction.options.getString('number');
params.game = game;
if (number) params.number = number;
const found = await flipzi('/v1/cards/search', params);
const card = found.data[0];
if (!card) return interaction.editReply('No card matched. Try the set number too.');
const priced = await flipzi(`/v1/cards/${card.id}/price`, { currency: 'eur' });
const price = priced.data.prices.find(p => p.grade === 'RAW');
const embed = new EmbedBuilder()
.setTitle(card.name)
.setDescription(`${card.set.name} · #${card.number}${card.rarity ? ` · ${card.rarity}` : ''}`)
.setThumbnail(card.image_url)
.setFooter({ text: 'Pricing data by Flipzi' });
if (price) {
embed.addFields(
{ name: 'Price (ungraded)', value: price.price_formatted, inline: true },
{ name: 'Market', value: price.market, inline: true },
{ name: 'Observed', value: `<t:${Math.floor(Date.parse(price.updated_at) / 1000)}:R>`, inline: true },
);
} else {
embed.addFields({ name: 'Price', value: 'No current price for this card.' });
}
await interaction.editReply({ embeds: [embed] });
} catch (err) {
await interaction.editReply(err.message);
}
});
client.login(process.env.DISCORD_TOKEN);
Three details matter more than the rest:
- Defer first. Discord drops an interaction that is not acknowledged within three seconds.
- Say which card you priced. The first search result is not always the card the member meant, so the embed shows set and number. For exact matches, ask for the collector number.
- An empty price list is not zero. Reply "no current price" rather than 0.00.
4. Graded and sold prices
The same handler extends with one parameter or one more call:
- Graded: add
grade=PSA_10to the price call and read the row with that grade. Pro and above. - What it sold for:
GET /v1/cards/{card_id}/soldreturns a value from completed eBay sales with the number of sales behind it. Pro and above. See APIs with eBay sold data. - By condition on Cardmarket:
GET /v1/cards/{card_id}/cardmarketreturns the cheapest and median asking price per grade and language. Ultra and above. See Cardmarket prices by condition. - Movers of the week:
GET /v1/market/moversfor a scheduled post. Ultra and above, 5 units a call.
An endpoint outside the key's plan answers 403 PLAN_FEATURE_LOCKED and is not billed, so the bot can offer a command and explain the refusal.
Caching and rate limits
The cache above answers a repeated question for ten minutes without a call. That is what keeps a busy server inside the per-minute limit (60 requests a minute on Basic). Follow the Cache-Control header on each response if you want the cache to track the data rather than a fixed time. A 429 means slow down, not retry at once; the handler tells the member to try again.
Do not call the API on every keystroke of an autocomplete option. If you add autocomplete, debounce it or serve it from your own list of names built from /v1/catalog/sets/{set_id}/cards.
Which plan does a bot need?
- Free: 500 units a month at 5 requests a minute. For building and testing; not for a bot that serves a community.
- Basic: 15,000 units a month, about 7,500 price checks before caching, with commercial use.
- Pro: adds graded and sold prices.
- Ultra: adds Cardmarket prices by condition and market movers.
Attribution ("Pricing data by Flipzi") is requested, not required. Current prices and allowances are on API pricing; storage and display rules are in caching, storage and licensing.
Get the bot answering today
A free key is enough to build and test the whole command. Move to a paid plan when it goes live in a server.
Get a free API key Try it in the playground Compare API plans