Install the Pokémon TCG SDK
masterInstall the pokemontcgsdk package via npm to use the wrapper for the Pokémon TCG API.
npm install --save pokemontcgsdkrepository·master·Indexed 41 days ago
https://github.com/pokemontcg/pokemon-tcg-sdk-javascriptA JavaScript wrapper for the Pokémon TCG API (pokemontcg.io) version 2.0.0. It provides programmatic access to cards, expansion sets, and metadata including supertypes, subtypes, types, and rarities.
Install the pokemontcgsdk package via npm to use the wrapper for the Pokémon TCG API.
npm install --save pokemontcgsdkUse the configure method to set your API key. This is required to authenticate your requests against the Pokémon TCG API.
import pokemon from 'pokemontcgsdk'
pokemon.configure({apiKey: '123abc'})You can retrieve all available values for the following categories using the .all() method:
pokemon.supertype.all()pokemon.subtype.all()pokemon.type.all()pokemon.rarity.all()// Examples of retrieving all values for specific categories
pokemon.supertype.all()
pokemon.subtype.all()
pokemon.type.all()
pokemon.rarity.all()The SDK provides several ways to interact with Card resources:
pokemon.card.find(id).pokemon.card.where({ q: 'query' }). You can pass pagination parameters like pageSize and page within the options object.pokemon.card.all({ q: 'query' }). This method automatically handles pagination and returns a flat array of card data without the pagination metadata.// Get a single card by ID
pokemon.card.find('base1-4')
.then(card => {
console.log(card.name) // "Charizard"
})
// Filter cards via the q parameter
pokemon.card.where({ q: 'name:blastoise' })
.then(result => {
console.log(result.data[0].name) // "Blastoise"
})
// Filter cards with pagination
pokemon.card.where({ q: 'name:blastoise', pageSize: 10, page: 3 })
.then(result => {
console.log(result.data[0].name) // "Blastoise"
})
// Automatically page through all matching cards
pokemon.card.all({ q: 'name:blastoise' })
.then((cards) => {
console.log(cards[0].name) // "Blastoise"
})The SDK provides several ways to interact with Set resources:
pokemon.set.find(id).pokemon.set.where({ q: 'query' }). You can pass pagination parameters like pageSize and page within the options object.pokemon.set.all({ q: 'query' }). This method automatically handles pagination and returns a flat array of set data without the pagination metadata.// Get a single set by ID
pokemon.set.find('base1')
.then(set => {
console.log(set.name) // "Base"
})
// Filter sets via the q parameter
pokemon.set.where({ q: 'series:base' })
.then(result => {
console.log(result.data[0].name) // "Base"
})
// Filter sets with pagination
pokemon.set.where({ q: 'series:base', pageSize: 1, page: 1 })
.then(result => {
console.log(result.data[0].name) // "Base"
})
// Automatically page through all matching sets
pokemon.set.all({ q: 'series:base' })
.then((cards) => {
console.log(cards[0].name) // "Base"
})Before making requests, you must authenticate the SDK by providing your API key using the configure method. This sets the apiKey globally for the SDK instance.
import pokemontcgsdk from 'pokemontcgsdk';
pokemontcgsdk.configure({
apiKey: 'YOUR_API_KEY'
});The SDK provides several top-level resource objects used to query different parts of the Pokémon TCG database. Each resource is a query builder instance.
Available resource objects:
card: Query Pokémon TCG cards.set: Query expansion sets.type: Query card types (e.g., Fire, Water).subtype: Query card subtypes.rarity: Query card rarities.supertype: Query card supertypes (e.g., Pokémon, Trainer, Energy).Example usage:
import pokemontcgsdk from 'pokemontcgsdk';
// Example: Fetching a specific card
const card = await pokemontcgsdk.card.get('xy1-1');