Celerium.APITCG
Celerium.APITCG

CI GitHub_Pages

PoshGallery_Version PoshGallery_Platforms PoshGallery_Downloads codeSize

Contributors Forks Stargazers Issues

GitHub_License


Logo

PowerShell Gallery · Report Bug · Request Feature


Buy me a coffee

Whether you use this project, have learned something from it, or just like it, please consider supporting it by buying me a coffee, so I can dedicate more time on open-source projects like this :)

Buy Me A Coffee

About The Project

The Celerium.APITCG PowerShell wrapper offers a way to read the data of the APITCG REST API, which covers the card data of 21 trading card games (Pokemon, Magic the Gathering, Yu-Gi-Oh!, One Piece, Lorcana, Riftbound, & more): the games, their sets, products (cards, sealed products, & accessories), market prices, & price history. This module serves to abstract away the details of interacting with the API in such a way that is consistent with PowerShell nomenclature. This gives collectors and PowerShell developers a convenient and familiar way of using the API to create price trackers, collection tools, & integrations.

  • :book: Celerium.APITCG project documentation can be found on Github Pages
  • :book: The API documentation can be found at docs.apitcg.com. The OpenAPI spec is published at https://docs.apitcg.com/openapi.json

A function is generated for every endpoint in the APITCG OpenAPI spec (apitcg.json) and every endpoint is tracked in the endpoints.csv file.

In order to maintain PowerShell best practices, only approved verbs are used and PowerShell’s verb-noun nomenclature is respected. Each noun is prefixed with APITCG in an attempt to prevent naming problems. The verb follows the HTTP method of the endpoint:

  • GET -> Get-APITCG*
  • POST -> New-APITCG*
  • PUT & PATCH -> Set-APITCG*
  • DELETE -> Remove-APITCG*

The API is read-only today, so every public function is a Get- function. Functions for the other methods are generated when the API adds such endpoints.

For example, one might access the /api/tcgs endpoint by running the following PowerShell command:

Get-APITCGTcg
  • Some functions cover more than one endpoint. Get-APITCGTcg -Id <slug>, Get-APITCGSet -Tcg <slug> -Id <id>, & Get-APITCGProduct -Id <id> use parameter sets to get a single item
  • By default only the data of a response is returned. Use -Raw to return the full response (success, data, total, & fallback)
  • Parameters are PascalCase (-UpdatedSince, -NarutoStatus, -AfterId) and are sent to the API in camelCase
  • Dates are converted for you: -UpdatedSince is sent as UTC, -From and -To of the price history as yyyy-MM-dd
  • The -Tcg parameters complete the 21 known games with the tab key, but accept any value so new games keep working
  • Items can be piped by their _id property, such as Get-APITCGProduct -Tcg pokemon -Name charizard | Get-APITCGHistoryPrice
  • The module works on Windows PowerShell 5.1 and PowerShell 7+ on Windows, Linux, & macOS

(back to top)


Install

This module supports Windows PowerShell 5.1 and PowerShell 7+ on Windows, Linux, & macOS.

  • Install the module from the PowerShell Gallery with PowerShellGet or PSResourceGet:

      Install-Module -Name Celerium.APITCG -Scope CurrentUser
    
      Install-PSResource -Name Celerium.APITCG
    
  • Import the module:

      Import-Module Celerium.APITCG
    
  • To use the module from a clone of this repository without installing it:

      Import-Module ./Celerium.APITCG/Celerium.APITCG.psd1
    

(back to top)


Quick start

An API key is required for every endpoint except the health check. Getting one is free, create an account at apitcg.com/register and copy your key from the API Key page of the Developer Platform.

Import-Module Celerium.APITCG

# Prompts for the key & keeps it as a SecureString for this session
Add-APITCGAPIKey

# The games, & the sets of one game
Get-APITCGTcg
Get-APITCGSet -Tcg 'one-piece'

# Search the cards of a game by a part of the name, or by the exact card code
Get-APITCGProduct -Tcg 'one-piece' -Name 'luffy' -Type 'card'
Get-APITCGProduct -Code 'OP03-070'

# The price history of a product, newest first
Get-APITCGProduct -Tcg 'pokemon' -Name 'charizard' -Limit 1 | Get-APITCGHistoryPrice -Limit 30

The examples folder has scripts that do more, including one that downloads the card images of a game.

(back to top)


Authentication & settings

The API key is sent in the x-api-key header of every request. The key is stored in memory as a SecureString and is only decrypted while a request is made. It is never written to the verbose output or to the Invoke_APITCGRequest_Parameters debug variable.

There are several ways to provide the key, later items replace earlier items:

  1. Add-APITCGAPIKey (alias Set-APITCGAPIKey) for the current session. Without parameters it prompts for the key, -ApiKey accepts text or the pipeline, & -ApiKeySecureString accepts a SecureString
  2. A saved configuration file created with Export-APITCGModuleSettings. The settings are loaded when the module is imported (Import-APITCGModuleSettings)
  3. The APITCG_API_KEY and APITCG_BASE_URI environment variables, which are read when the module is imported and replace the saved configuration
# For this session
Add-APITCGAPIKey

# Saved for every session of the current user
Add-APITCGAPIKey
Export-APITCGModuleSettings

# From the environment (CI, containers, scheduled tasks)
$env:APITCG_API_KEY = '<your key>'
Import-Module Celerium.APITCG -Force

# Verify the connection (this uses 1 request of the monthly quota)
Test-APITCGAPIKey
Setting Default Command / environment variable
API key none Add-APITCGAPIKey / APITCG_API_KEY
Base URI https://api.apitcg.com Add-APITCGBaseURI (alias Set-APITCGBaseURI) / APITCG_BASE_URI
Configuration file ~\Celerium.APITCG\config.psd1 on Windows, ~/.Celerium.APITCG/config.psd1 on Linux & macOS Export-APITCGModuleSettings, Import-APITCGModuleSettings, Get-APITCGModuleSettings, Remove-APITCGModuleSettings
  • On Windows the saved key is encrypted with the Windows Data Protection API, so the file only works for the same user on the same computer. On Linux & macOS the key in the file is not encrypted, use the environment variable or a secret store instead
  • The base URI only needs to change for a proxy or a mock server. It must use https
  • Remove-APITCGAPIKey, Remove-APITCGBaseURI, and Remove-APITCGModuleSettings remove the values again
  • Importing the module never calls the API
  • Never commit an API key. Use the APITCG_API_KEY environment variable or a secret of your CI system

(back to top)


Rate limits & monthly quota

There are two separate limits:

Limit Value What the module does
Requests per minute 300 per IP address (RateLimit-Policy: 300;w=60) Waits for the Retry-After seconds (at most 120 seconds) & tries the request again when the API answers 429. While paging with -AllResults it also sleeps until the window resets when no requests are left
Requests per month Free 1,000, Starter 20,000, Pro 200,000 (see plans) A 429 with Request limit reached for this month. is never retried, the error is thrown straight away. The quota resets on the 1st of each month at 00:00 Chile time
  • Each request that succeeds counts once against the monthly quota. Requests that fail (4xx or 5xx), such as an unknown product, do not count. The health check does not use a key
  • The API sends the RateLimit & RateLimit-Policy headers with every response. The module keeps the last values, Get-APITCGRateLimit returns them without making a request:

      Get-APITCGTcg | Out-Null
      Get-APITCGRateLimit
    
      # Limit Remaining ResetSeconds Policy  ResetAt              RetrievedAt
      # ----- --------- ------------ ------  -------              -----------
      #   300       299           58 300;w=60 2026-12-03 18:01:00  2026-12-03 18:00:02
    
  • The monthly quota is not part of the headers, so the module can not show it. Follow the usage on the Developer Platform
  • Failed GET requests with a 502, 503, or 504 status or a network error are retried up to 3 times with an exponential backoff
  • Plan your requests. -AllResults uses one request per 100 items, so downloading a whole game takes many requests. Use filters and -UpdatedSince to keep the number of requests low

(back to top)


Paging

List endpoints return at most 100 items per request. Use -Limit and -Page to read a page yourself, or -AllResults to let the module request every page:

# One page of 10 items
Get-APITCGProduct -Tcg 'one-piece' -Type 'card' -Limit 10 -Page 2

# Every card of one game
Get-APITCGProduct -Tcg 'one-piece' -Type 'card' -AllResults

# Only what changed since the last sync
Get-APITCGProduct -UpdatedSince (Get-Date).AddDays(-7) -AllResults
  • Get-APITCGProduct -AllResults pages with a cursor, which is the way the API recommends to copy a large part of the catalog. The results are sorted by _id (-SortBy and -SortOrder can only be _id and asc) and each request starts after the last _id of the previous request (-AfterId, default 0). The cursor stops when a page has fewer items than the limit. The total is not known with a cursor, so the progress bar has no percentage
  • Other paged endpoints use page and limit, the paging stops at the last page or when the total has been reached
  • -Raw -AllResults returns one object with success, total, and data holding every item
  • -Raw without -AllResults returns the first response including the total, which is a cheap way to count: (Get-APITCGProduct -Tcg 'one-piece' -Limit 1 -Raw).total
  • Get-APITCGTcg and Get-APITCGSet return everything in one request, the price history returns a plain list (use -From, -To, and -Limit)

(back to top)


Supported functions

Every function is tracked in endpoints.csv, the generated documentation has a page for each function.

Function Endpoint Description
Get-APITCGHealth GET / Checks that the API is up, no API key needed
Get-APITCGTcg GET /api/tcgs, GET /api/tcgs/{id} Lists the games, or gets one game by its slug (-Id)
Get-APITCGSet GET /api/{tcg}/sets, GET /api/{tcg}/sets/{id} Lists the sets of a game (-Tcg), or gets one set (-Id)
Get-APITCGProduct GET /api/products, GET /api/products/{id} Searches the cards, sealed products, & accessories with filters (-Type -Tcg -Set -Name -Code -UpdatedSince -AfterId -NarutoStatus -IncludeSuperseded -Populate -Limit -Page -SortBy -SortOrder), supports -AllResults, or gets one product (-Id)
Get-APITCGHistoryPrice GET /api/history-prices/{productId} The daily price history of a product (-ProductId -From -To -Limit)

The following functions are used by the module and are also exported:

Function Description
Add-APITCGAPIKey, Get-APITCGAPIKey, Remove-APITCGAPIKey, Test-APITCGAPIKey Manage & test the API key (alias Set-APITCGAPIKey)
Add-APITCGBaseURI, Get-APITCGBaseURI, Remove-APITCGBaseURI Manage the base URI (alias Set-APITCGBaseURI)
Export-APITCGModuleSettings, Import-APITCGModuleSettings, Get-APITCGModuleSettings, Remove-APITCGModuleSettings, Initialize-APITCGModuleSettings Save & load the settings
Get-APITCGRateLimit, ConvertTo-APITCGRateLimit The rate limit of the last response
Invoke-APITCGRequest Makes the API requests of all functions (retries, paging, unwrapping)
ConvertTo-APITCGQueryString, Get-APITCGUriParameter, Get-APITCGResponseHeader Helpers that build the query string and read headers

Every public function has -Raw and comment based help, for example Get-Help Get-APITCGProduct -Full.

(back to top)


Examples

The examples folder has scripts for the most common tasks. They use read-only requests, work on Windows PowerShell 5.1 and PowerShell 7+, and import the module from this repository when it is not installed.

Script Description
Invoke-ExampleAPITCGTcg.ps1 Health check, the games, & their sets
Invoke-ExampleAPITCGProduct.ps1 Search by name or code, the released Naruto cards, sealed products, & an incremental sync with -UpdatedSince
Invoke-ExampleAPITCGPriceHistory.ps1 Finds a product, returns its price history, & saves it to CSV
Save-APITCGCardImage.ps1 Downloads the card images of one or more games or sets
# See how many API requests downloading One Piece would use, nothing is downloaded
.\examples\Save-APITCGCardImage.ps1 -Tcg 'one-piece' -WhatIf

# Download the small images of one set
.\examples\Save-APITCGCardImage.ps1 -Tcg 'one-piece' -Set 'one-piece-pillars-of-strength' -Size small -OutputPath C:\Images

:warning: Downloading the images of a game takes about one API request per 100 products and the Free plan has 1,000 requests per month. Save-APITCGCardImage.ps1 estimates the requests and asks for confirmation first. The API key is never sent to the image servers.

(back to top)


Development

Prerequisites

./build/Install-Prerequisites.ps1

Installs the latest stable ModuleBuilder, Pester, PSScriptAnalyzer, & Microsoft.PowerShell.PlatyPS from the PowerShell Gallery.

Scripts

Script Description
build/Invoke-ModuleBuild.ps1 Builds the module with ModuleBuilder into build/Celerium.APITCG/<Version>
build/Invoke-PesterTests.ps1 Runs the Pester tests against the source (-BuildTarget notBuilt) or built (-BuildTarget built) module
build/New-PublicFunctions.ps1 Generates the public functions, the manifest lists, & docs/endpoints.csv from docs/apitcg.json
build/Get-APITCGSpec.ps1 Downloads the latest spec from https://docs.apitcg.com/openapi.json to docs/apitcg.json
build/Compare-APITCGSpec.ps1 Compares the local spec with the online spec
build/Invoke-HelpContent.ps1 Generates the documentation in docs (function pages, module page, external help)
build/Publish-CeleriumModule.ps1 Publishes the built module to the PowerShell Gallery & creates the GitHub release
# Test the source & the built module
./build/Invoke-PesterTests.ps1 -Version 1.0.0 -BuildTarget notBuilt
./build/Invoke-ModuleBuild.ps1 -Version 1.0.0
./build/Invoke-PesterTests.ps1 -Version 1.0.0 -BuildTarget built

# Follow the spec of the API
./build/Get-APITCGSpec.ps1
./build/Compare-APITCGSpec.ps1
./build/New-PublicFunctions.ps1

# Update the documentation
./build/Invoke-HelpContent.ps1
  • The public functions in Celerium.APITCG/Public are generated, change the spec or the generator and run build/New-PublicFunctions.ps1 instead of editing them. Files that are no longer needed are moved to build/Archive and never deleted
  • The tests do not call the API. The Live tests (-IncludeTag Live) make at most 8 requests with the key in APITCG_API_KEY, and the Online tests need the published documentation
  • The tests must pass on Windows PowerShell 5.1 and PowerShell 7+

Release

  1. Update ModuleVersion in Celerium.APITCG/Celerium.APITCG.psd1 and the release notes.
  2. Push a tag that matches the version, such as v1.0.0, or run the Release workflow manually (a dry run is the default and publishes nothing).
  3. The workflow runs the full test matrix, builds the module, publishes it to the PowerShell Gallery, creates the GitHub release v<Version> with the zipped module attached, and adds the release notes to CHANGELOG.md.

A version is never published without a GitHub release. When a run fails after the module was published, run it again and only the missing release is created.

Continuous integration

Workflow When What
ci.yml Push & pull request to main, called by release.yml Checks that the generated code is up to date, then tests the source & built module on the matrix below
release.yml Tag v*.*.*, manual CI, then publish to the PowerShell Gallery, create the GitHub release, & update the changelog
live.yml Weekly, manual The read-only Live tests against the real API (skipped without APITCG_API_KEY)
spec.yml Weekly, manual Fails when docs/apitcg.json differs from the online spec
docs.yml Push to main, manual Regenerates the documentation in docs
powershell.yml Push & pull request to main, weekly PSScriptAnalyzer results in the code scanning tab
changelog.yml Release published, called by release.yml Adds the release notes to CHANGELOG.md

The CI test matrix:

Name Runner Shell
Windows PowerShell 5.1 windows-latest powershell
Windows PowerShell 7+ windows-latest pwsh
Linux PowerShell 7+ ubuntu-latest pwsh
macOS PowerShell 7+ macos-latest pwsh

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

Please read the Contributing guide and the Code of conduct before opening a pull request. Report security problems as described in the Security policy.

Don’t forget to give the project a star! Thanks again!

(back to top)


License

Distributed under the MIT License. See LICENSE for more information.

This project is not affiliated with APITCG. The trading card names, images, and prices belong to their owners and are subject to the terms of the API.

(back to top)


Table of contents