Pokémon TCG SDK for JavaScript

repository·master·Indexed 41 days ago

https://github.com/pokemontcg/pokemon-tcg-sdk-javascript

A 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.

Tokens
1.4K
Snippets
7
Records
7
Agent score
50%

What's inside Pokémon TCG SDK

  1. Retrieve Supertypes, Subtypes, Types, and Rarities

    master

    You can retrieve all available values for the following categories using the .all() method:

    • Supertypes: pokemon.supertype.all()
    • Subtypes: pokemon.subtype.all()
    • Types: pokemon.type.all()
    • Rarity: pokemon.rarity.all()
    // Examples of retrieving all values for specific categories
    pokemon.supertype.all()
    pokemon.subtype.all()
    pokemon.type.all()
    pokemon.rarity.all()
  2. Retrieve Card data

    master

    The SDK provides several ways to interact with Card resources:

    • Find a single card by ID: Use pokemon.card.find(id).
    • Filter cards: Use pokemon.card.where({ q: 'query' }). You can pass pagination parameters like pageSize and page within the options object.
    • Retrieve all cards (Automatic Pagination): Use 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"
        })
  3. Retrieve Set data

    master

    The SDK provides several ways to interact with Set resources:

    • Find a single set by ID: Use pokemon.set.find(id).
    • Filter sets: Use pokemon.set.where({ q: 'query' }). You can pass pagination parameters like pageSize and page within the options object.
    • Retrieve all sets (Automatic Pagination): Use 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"
        })
  4. Access API resources via the Pokémon TCG SDK

    master

    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');