Documentation
¶
Overview ¶
Package tcgplayer is a client for the TCGplayer catalog and pricing API, and defines the format of the catalog dumps cmd/tcgdumper writes.
Index ¶
- Constants
- Variables
- func ProductTypes(category int) []string
- func SealedProductTypes(category int) []string
- func SinglesProductTypes(category int) []string
- type APIError
- type BaseResponse
- type CatalogDump
- type Category
- type Client
- func (tcg *Client) Get(ctx context.Context, link string) (*BaseResponse, error)
- func (tcg *Client) GetCategoriesDetails(ctx context.Context, categoryIDs []int) ([]Category, error)
- func (tcg *Client) GetMarketPricesByProducts(ctx context.Context, productIDs []int) ([]ProductPriceSet, error)
- func (tcg *Client) GetMarketPricesBySKUs(ctx context.Context, skuIDs []int) ([]SKUPriceSet, error)
- func (tcg *Client) GetProductsDetails(ctx context.Context, productIDs []int, includeSkus bool) ([]Product, error)
- func (tcg *Client) ListAllCategoryGroups(ctx context.Context, category, offset int) ([]Group, error)
- func (tcg *Client) ListAllProducts(ctx context.Context, category int, productTypes []string, includeSkus bool, ...) ([]Product, error)
- func (tcg *Client) ListCategoryConditions(ctx context.Context, category int) ([]Condition, error)
- func (tcg *Client) ListCategoryLanguages(ctx context.Context, category int) ([]Language, error)
- func (tcg *Client) ListCategoryPrintings(ctx context.Context, category int) ([]Printing, error)
- func (tcg *Client) ListCategoryRarities(ctx context.Context, category int) ([]Rarity, error)
- func (tcg *Client) ListProductSKUs(ctx context.Context, productID int) ([]SKU, error)
- func (tcg *Client) TotalCategories(ctx context.Context) (int, error)
- func (tcg *Client) TotalGroups(ctx context.Context, category int) (int, error)
- func (tcg *Client) TotalProducts(ctx context.Context, category int, productTypes []string) (int, error)
- type Condition
- type Group
- type Language
- type Printing
- type Product
- type ProductPriceSet
- type Rarity
- type SKU
- type SKUPriceSet
Constants ¶
const ( // MaxItemsInResponse is the largest page a listing endpoint returns MaxItemsInResponse = 100 // MaxIDsInRequest is the most ids a batched endpoint accepts MaxIDsInRequest = 250 )
const ( CategoryMagic = iota + 1 CategoryYuGiOh CategoryPokemon CategoryAxisAllies CategoryBoardgames CategoryDDMiniatures CategoryEpic CategoryHeroclix CategoryMonsterpocalypse CategoryRedakai CategoryStarWarsMiniatures CategoryWorldOfWarcraftMiniatures CategoryWoW CategorySupplies CategoryOrganizersStores CategoryCardfightVanguard CategoryForceOfWill CategoryDiceMasters CategoryFutureCardBuddyFight CategoryWeissSchwarz CategoryTCGplayer CategoryDragonBallZ CategoryFinalFantasy CategoryUniVersus CategoryStarWarsDestiny CategoryDragonBallSuper CategoryDragoborne CategoryFunko CategoryMetaX CategoryCardSleeves CategoryDeckBoxes CategoryCardStorageTins CategoryLifeCounters CategoryPlaymats CategoryZombieWorldOrder CategoryTheCasterChronicles CategoryMyLittlePony CategoryWarhammerBooks CategoryWarhammerBigBoxGames CategoryWarhammerBoxSets CategoryWarhammerClampacks CategoryCitadelPaints CategoryCitadelTools CategoryWarhammerGameAccessories CategoryBooks CategoryExodus CategoryLightseekers CategoryProtectivePages CategoryStorageAlbums CategoryCollectibleStorage CategorySupplyBundles CategoryMunchkin CategoryWarhammerAgeOfSigmarChampions CategoryArchitect CategoryBulkLots CategoryTransformers CategoryBakugan CategoryKeyForge CategoryChronoClashSystem CategoryArgentSaga CategoryFleshAndBlood CategoryDigimon CategoryAlternateSouls CategoryGateRuler CategoryMetaZoo CategoryWIXOSS CategoryOnePiece CategoryMarvelComics CategoryDCComics CategoryLorcana CategoryBattleSpiritsSaga CategoryShadowverseEvolve CategoryGrandArchive CategoryAkora CategoryKryptik CategorySorceryContestedRealm CategoryAlphaClash CategoryStarWarsUnlimited CategoryDragonBallSuperFusionWorld CategoryUnionArena CategoryTCGplayerSupplies CategoryElestrals CategoryNeopetsBattledome CategoryPokemonJapan CategoryGundam CategoryHololive CategoryGodzilla CategoryRiftbound CategoryCookieRunBraverse CategoryPalworld CategoryCyberpunk )
All active categories on the platform
Variables ¶
var ( TokenURL = "https://api.tcgplayer.com/token" CatalogCategoriesURL = "https://api.tcgplayer.com/" + tcgAPIVersion + "/catalog/categories" CatalogProductsURL = "https://api.tcgplayer.com/" + tcgAPIVersion + "/catalog/products" CatalogGroupsURL = "https://api.tcgplayer.com/" + tcgAPIVersion + "/catalog/groups" PricingProductURL = "https://api.tcgplayer.com/" + tcgAPIVersion + "/pricing/product" PricingSKUURL = "https://api.tcgplayer.com/" + tcgAPIVersion + "/pricing/sku" )
Endpoint URLs, overridable for testing
var AllProductTypes = []string{
"3D Tokens",
"3x Magic Booster Packs",
"All 5 Intro Packs",
"BakuCores",
"Booster Battle Pack",
"Booster Box",
"Booster Pack",
"Box Sets",
"Bulk Lot",
"Cards",
"D & D Miniatures",
"Dragoborne Sealed Products",
"Dragon Ball Super Sealed Products",
"Dragon Ball Super Singles",
"Fat Pack",
"Final Fantasy Sealed Products",
"Final Fantasy Singles",
"Funko Products",
"Gift Card",
"Heroclix",
"Intro Pack",
"Intro Pack Display",
"Magic Booster Box Case",
"Magic Deck Pack",
"Osprey Publishing",
"Precon/Event Decks",
"Sealed Product",
"Sealed Products",
"Star Wars: Destiny Sealed Products",
"Star Wars: Destiny Singles",
"Supplies",
"Tin",
"Tokens",
"UFS Sealed Products",
"UFS Singles",
"YGO Start Decks",
}
AllProductTypes lists every product type name the platform uses. No category files products under all of them; ProductTypes reports the ones a given category actually uses.
var ProductTypesByCategory = map[int][]string{ CategoryMagic: {"3x Magic Booster Packs", "All 5 Intro Packs", "Booster Battle Pack", "Booster Box", "Booster Pack", "Box Sets", "Cards", "Fat Pack", "Intro Pack", "Intro Pack Display", "Magic Booster Box Case", "Magic Deck Pack", "Precon/Event Decks", "Sealed Products"}, CategoryYuGiOh: {"Booster Box", "Booster Pack", "Box Sets", "Cards", "Fat Pack", "Intro Pack", "Magic Booster Box Case", "Sealed Products", "Tin", "YGO Start Decks"}, CategoryPokemon: {"Cards", "Sealed Products"}, CategoryDDMiniatures: {"D & D Miniatures"}, CategoryEpic: {"Cards"}, CategoryHeroclix: {"Heroclix", "Sealed Products"}, CategoryWoW: {"Booster Box", "Booster Pack", "Cards", "Sealed Products"}, CategoryCardfightVanguard: {"Cards", "Intro Pack", "Sealed Products"}, CategoryForceOfWill: {"Cards", "Sealed Products"}, CategoryDiceMasters: {"Cards", "Sealed Products"}, CategoryFutureCardBuddyFight: {"Cards", "Sealed Products"}, CategoryWeissSchwarz: {"Cards", "Sealed Products"}, CategoryTCGplayer: {"Gift Card"}, CategoryDragonBallZ: {"Cards", "Sealed Products"}, CategoryFinalFantasy: {"Final Fantasy Sealed Products", "Final Fantasy Singles"}, CategoryUniVersus: {"UFS Sealed Products", "UFS Singles"}, CategoryStarWarsDestiny: {"Star Wars: Destiny Sealed Products", "Star Wars: Destiny Singles"}, CategoryDragonBallSuper: {"Dragon Ball Super Sealed Products", "Dragon Ball Super Singles"}, CategoryDragoborne: {"Cards", "Dragoborne Sealed Products"}, CategoryFunko: {"Funko Products"}, CategoryMetaX: {"Cards", "Sealed Products"}, CategoryCardSleeves: {"Supplies"}, CategoryDeckBoxes: {"Supplies"}, CategoryCardStorageTins: {"Supplies"}, CategoryLifeCounters: {"3D Tokens", "Sealed Products", "Supplies", "Tokens"}, CategoryPlaymats: {"Supplies"}, CategoryZombieWorldOrder: {"Cards", "Sealed Products"}, CategoryTheCasterChronicles: {"Cards", "Sealed Products"}, CategoryMyLittlePony: {"Sealed Products"}, CategoryBooks: {"Osprey Publishing"}, CategoryExodus: {"Cards", "Sealed Products"}, CategoryLightseekers: {"Cards", "Sealed Products"}, CategoryProtectivePages: {"Supplies"}, CategoryStorageAlbums: {"Supplies"}, CategoryCollectibleStorage: {"Supplies"}, CategorySupplyBundles: {"Supplies"}, CategoryMunchkin: {"Cards", "Sealed Products"}, CategoryWarhammerAgeOfSigmarChampions: {"Cards", "Sealed Products"}, CategoryBulkLots: {"Bulk Lot"}, CategoryTransformers: {"Cards", "Sealed Products"}, CategoryBakugan: {"BakuCores", "Cards", "Sealed Products"}, CategoryKeyForge: {"Sealed Products"}, CategoryChronoClashSystem: {"Cards", "Sealed Products"}, CategoryArgentSaga: {"Cards", "Sealed Products"}, CategoryFleshAndBlood: {"Cards", "Sealed Products"}, CategoryDigimon: {"Cards", "Sealed Products"}, CategoryAlternateSouls: {"Sealed Products"}, CategoryGateRuler: {"Cards", "Sealed Products"}, CategoryMetaZoo: {"Cards", "Sealed Products"}, CategoryWIXOSS: {"Cards", "Sealed Products"}, CategoryOnePiece: {"Cards", "Sealed Products"}, CategoryLorcana: {"Cards", "Sealed Products"}, CategoryBattleSpiritsSaga: {"Cards", "Sealed Product"}, CategoryShadowverseEvolve: {"Cards", "Sealed Product"}, CategoryGrandArchive: {"Cards", "Sealed Product"}, CategoryAkora: {"Cards", "Sealed Product"}, CategoryKryptik: {"Cards", "Sealed Product"}, CategorySorceryContestedRealm: {"Cards", "Sealed Products"}, CategoryAlphaClash: {"Cards", "Sealed Products"}, CategoryStarWarsUnlimited: {"Cards", "Sealed Products"}, CategoryDragonBallSuperFusionWorld: {"Cards", "Sealed Products"}, CategoryUnionArena: {"Cards", "Sealed Products"}, CategoryTCGplayerSupplies: {"Sealed Products"}, CategoryElestrals: {"Cards", "Sealed Products"}, CategoryPokemonJapan: {"Cards", "Sealed Products"}, CategoryGundam: {"Cards", "Sealed Products"}, CategoryHololive: {"Cards", "Sealed Products"}, CategoryGodzilla: {"Cards", "Sealed Products"}, CategoryRiftbound: {"Cards", "Sealed Products"}, CategoryCookieRunBraverse: {"Cards", "Sealed Products"}, }
ProductTypesByCategory holds the product types each category files its products under. Asking for only these keeps a dump from paging types the category never uses, and keeps it from missing the ones it does: the entries below were read off the platform and each accounts for its category's whole product count. Categories absent from the map are ones whose vocabulary is not known; ProductTypes falls back to every name for them, which a caller counting its results will find comes up short.
var ProductTypesSealed = []string{
"Booster Box",
"Booster Pack",
"Sealed Products",
"Intro Pack",
"Fat Pack",
"Box Sets",
"Precon/Event Decks",
"Magic Deck Pack",
"Magic Booster Box Case",
"All 5 Intro Packs",
"Intro Pack Display",
"3x Magic Booster Packs",
"Booster Battle Pack",
}
ProductTypesSealed lists the sealed product types Magic files products under. Prefer SealedProductTypes: a category files its own set, and one missing from this list is one whose products go unseen.
var ProductTypesSingles = []string{"Cards"}
ProductTypesSingles lists the product type holding single cards for the categories that name it the common way. Prefer SinglesProductTypes, which answers for the categories naming it after themselves too.
Functions ¶
func ProductTypes ¶ added in v0.1.2
ProductTypes returns the product types the given category files its products under, or every known type when the category is not listed.
func SealedProductTypes ¶ added in v0.1.2
SealedProductTypes returns the product types the given category files everything other than single cards under, sealed products above all.
func SinglesProductTypes ¶ added in v0.1.2
SinglesProductTypes returns the product types the given category files single cards under. It is empty for the categories that sell none, such as supplies and storage.
Types ¶
type APIError ¶ added in v0.1.0
APIError is a request the API answered with an error envelope, keeping the http status the message arrived under
type BaseResponse ¶
type BaseResponse struct {
TotalItems int `json:"totalItems"`
Success bool `json:"success"`
Errors []string `json:"errors"`
Results json.RawMessage `json:"results"`
}
BaseResponse is the envelope every endpoint wraps its payload in. Results is left raw for the caller to decode into the type the endpoint returns.
type CatalogDump ¶ added in v0.1.0
type CatalogDump struct {
Category Category `json:"category"`
Conditions []Condition `json:"conditions"`
Languages []Language `json:"languages"`
Printings []Printing `json:"printings"`
Rarities []Rarity `json:"rarities"`
Groups []Group `json:"groups"`
Products []Product `json:"products"`
}
CatalogDump is the envelope cmd/tcgdumper writes for a category. Naming it here keeps the program that writes a dump and the programs that read one on a single definition of the format, rather than each carrying its own.
func (*CatalogDump) PrintingNames ¶ added in v0.1.0
func (d *CatalogDump) PrintingNames() map[int][]string
PrintingNames maps each product to the distinct printing names its skus carry, ordered as the dump lists the category's printings. A printing the dump does not list for a product is one that product is not sold in.
type Category ¶
type Category struct {
CategoryID int `json:"categoryId"`
Name string `json:"name"`
ModifiedOn string `json:"modifiedOn"`
DisplayName string `json:"displayName"`
SeoCategoryName string `json:"seoCategoryName"`
SealedLabel string `json:"sealedLabel"`
NonSealedLabel string `json:"nonSealedLabel"`
ConditionGuideURL string `json:"conditionGuideUrl"`
IsScannable bool `json:"isScannable"`
Popularity int `json:"popularity"`
}
Category is a game or product line the catalog is split into, such as Magic
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the TCGplayer API, holding the credentials every call needs. It acquires and refreshes bearer tokens on demand, holds requests to a rate limit, and retries the ones that fail transiently. A Client is safe for concurrent use.
func NewClient ¶
NewClient returns a Client authenticating with the given key pair. Both keys are required. No request is made here: the first token is acquired by the first call that needs one.
func (*Client) Get ¶
Get performs an authenticated GET request against link and parses the response envelope, leaving its payload for the caller to decode
func (*Client) GetCategoriesDetails ¶
GetCategoriesDetails returns the details of the given categories, at most MaxIDsInRequest of them per call
func (*Client) GetMarketPricesByProducts ¶
func (tcg *Client) GetMarketPricesByProducts(ctx context.Context, productIDs []int) ([]ProductPriceSet, error)
GetMarketPricesByProducts returns the current pricing of the given products, at most MaxIDsInRequest of them per call
func (*Client) GetMarketPricesBySKUs ¶
GetMarketPricesBySKUs returns the current pricing of the given skus, at most MaxIDsInRequest of them per call
func (*Client) GetProductsDetails ¶
func (tcg *Client) GetProductsDetails(ctx context.Context, productIDs []int, includeSkus bool) ([]Product, error)
GetProductsDetails returns the details of the given products, at most MaxIDsInRequest of them per call. Pass includeSkus to have each product carry the skus it is sold as.
func (*Client) ListAllCategoryGroups ¶
func (tcg *Client) ListAllCategoryGroups(ctx context.Context, category, offset int) ([]Group, error)
ListAllCategoryGroups returns one page of a category's groups, starting at offset and holding at most MaxItemsInResponse of them. Pair it with TotalGroups to walk a whole category.
func (*Client) ListAllProducts ¶
func (tcg *Client) ListAllProducts(ctx context.Context, category int, productTypes []string, includeSkus bool, offset int) ([]Product, error)
ListAllProducts returns one page of a category's products, starting at offset and holding at most MaxItemsInResponse of them. Pair it with TotalProducts to walk a whole category.
func (*Client) ListCategoryConditions ¶ added in v0.0.3
ListCategoryConditions returns the conditions a category's skus reference
func (*Client) ListCategoryLanguages ¶ added in v0.0.3
ListCategoryLanguages returns the languages a category's skus reference
func (*Client) ListCategoryPrintings ¶
ListCategoryPrintings returns the printings a category's skus reference
func (*Client) ListCategoryRarities ¶ added in v0.0.3
ListCategoryRarities returns the rarities a category's products carry
func (*Client) ListProductSKUs ¶
ListProductSKUs returns the skus a product is sold as
func (*Client) TotalCategories ¶
TotalCategories reports how many categories the platform holds
func (*Client) TotalGroups ¶
TotalGroups reports how many groups a category holds
type Condition ¶ added in v0.0.3
type Condition struct {
ConditionID int `json:"conditionId"`
Name string `json:"name"`
Abbreviation string `json:"abbreviation"`
DisplayOrder int `json:"displayOrder"`
}
Condition is a grade a category's products are sold in, such as Near Mint
type Group ¶
type Group struct {
GroupID int `json:"groupId"`
Name string `json:"name"`
Abbreviation string `json:"abbreviation"`
Supplemental bool `json:"supplemental"`
PublishedOn string `json:"publishedOn"`
ModifiedOn string `json:"modifiedOn"`
CategoryID int `json:"categoryId"`
}
Group is a set, expansion or other collection a category files its products under
func (Group) ReleaseDate ¶ added in v0.1.0
ReleaseDate is the group's publish date without the time of day. ReleaseDate is the day the group was published, without the time of day
type Language ¶ added in v0.0.3
type Language struct {
LanguageID int `json:"languageId"`
Name string `json:"name"`
Abbreviation string `json:"abbr"`
}
Language is a language a category's products are printed in
type Printing ¶
type Printing struct {
PrintingID int `json:"printingId"`
Name string `json:"name"`
DisplayOrder int `json:"displayOrder"`
ModifiedOn string `json:"modifiedOn"`
}
Printing is a finish a category's cards are printed in, such as Foil
type Product ¶
type Product struct {
ProductID int `json:"productId"`
Name string `json:"name"`
CleanName string `json:"cleanName"`
ImageURL string `json:"imageUrl"`
GroupID int `json:"groupId"`
URL string `json:"url"`
ModifiedOn string `json:"modifiedOn"`
// Never returned by the API, which does not report the product type a
// product is filed under; tcgdumper stamps the type it fetched the
// product by, so it is present in catalog dumps only
ProductType string `json:"productType,omitempty"`
// Only available for catalog API calls
Skus []SKU `json:"skus,omitempty"`
// Only available for catalog API calls
ExtendedData []struct {
Name string `json:"name"`
DisplayName string `json:"displayName"`
Value string `json:"value"`
} `json:"extendedData,omitempty"`
}
Product is a single item in the catalog, a card or a sealed product
type ProductPriceSet ¶
type ProductPriceSet struct {
ProductID int `json:"productId"`
LowPrice float64 `json:"lowPrice"`
MarketPrice float64 `json:"marketPrice"`
MidPrice float64 `json:"midPrice"`
DirectLowPrice float64 `json:"directLowPrice"`
SubTypeName string `json:"subTypeName"`
}
ProductPriceSet is the current pricing of one product, for one sub type
type Rarity ¶ added in v0.0.3
type Rarity struct {
RarityID int `json:"rarityId"`
DisplayText string `json:"displayText"`
DBValue string `json:"dbValue"`
}
Rarity is a rarity a category's cards are printed at
type SKU ¶
type SKU struct {
SKUID int `json:"skuId"`
ProductID int `json:"productId"`
LanguageID int `json:"languageId"`
PrintingID int `json:"printingId"`
ConditionID int `json:"conditionId"`
}
SKU is a sellable variant of a product: one combination of language, printing and condition
type SKUPriceSet ¶
type SKUPriceSet struct {
SKUID int `json:"skuId"`
LowPrice float64 `json:"lowPrice"`
LowestShipping float64 `json:"lowestShipping"`
LowestListingPrice float64 `json:"lowestListingPrice"`
MarketPrice float64 `json:"marketPrice"`
DirectLowPrice float64 `json:"directLowPrice"`
}
SKUPriceSet is the current pricing of one sku