Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

scryfall-sdk

ChiriVulpes411MIT5.0.3TypeScript support: included

A Node.js SDK for https://scryfall.com/docs/api written in Typescript.

magic, magic the gathering, magic-the-gathering, gathering, api, mtgsdk, typescript, card, cards, scryfall, scry

readme

scryfall-sdk

npm GitHub issues Travis

A Node.js SDK for Scryfall written in Typescript.

As of August 8th, 2024, all features described in the Scryfall documentation should be supported. If you see something that isn't, make an issue!

Installation

npm install scryfall-sdk

Using a node.js version older than v18?

Install the axios dependency alongside scryfall-sdk and it will automatically use it.

Basic Example Usage

import * as Scry from "scryfall-sdk";

// ...in some function somewhere...
const chalice = await Scry.Cards.byName("Chalice of the Void");
console.log(chalice.name, chalice.set); // "Chalice of the Void", "a25"

const prints = await chalice.getPrints();
console.log(prints.length); // 7

[!IMPORTANT]
Scryfall requires that all applications provide an agent, except if they are executing from web browser JavaScript.

If this is true for your application, you must set your agent before making any requests:

Scry.setAgent("MyAmazingAppName", "1.0.0");

Full Documentation

scryfall-sdk supports all features of Scryfall, along with automatically paginating through results, downloading bulk data streams, and more. See the documentation for information on everything you can do.

Know the endpoint you want, but not sure what it looks like in scryfall-sdk? Well, you're in luck: Scryfall-SDK Equivalents for Scryfall Routes

Contributing

Thanks for wanting to help out! Here's the setup you'll have to do:

git clone https://github.com/ChiriVulpes/scryfall-sdk
cd scryfall-sdk
npm install

You can now make changes to the repository.

To compile, then test:

gulp build

To compile and then test on every file change:

gulp watch

MIT License

Copyright 2017-2024 Chiri Vulpes

changelog

v5.0.3 (January 11th, 2025)

  • Updated PromoType to reflect the current Scryfall dataset. (Thanks mcgrue!)

v5.0.2 (August 18th, 2024)

  • Fixed missing hybrid field in card symbols.

v5.0.1 (August 11th, 2024)

  • Add the potentiality of colourless mana ("C") to Card.produced_mana.

v5.0.0 (August 8th, 2024)

  • Added support for setting the agent name due to Scryfall's new requirements via Scry.setAgent(name, version)(./DOCUMENTATION.md#scrysetagent-agent-string-version-string-void-). All applications using scryfall-sdk that are not running on clientside in the browser must provide an agent name & version.

v4.2.1 (December 9th, 2023)

  • Fixed MagicEmitters (IE, what's returned by Cards.search()) erroring if not every possible event has a listener registered, thanks to #69 by lordnox.

v4.2.0 (October 23rd, 2023)

v4.1.1 (February 25th, 2023)

v4.1.0 (February 19th, 2023)

  • Scryfall-sdk is now once again compatible with older node versions. If you install axios alongside scryfall-sdk, it will automatically use it. Trying to use scryfall-sdk with an older node version without having axios installed will throw an error.
  • Thanks to Kevin Lowe via #62, added full-text query support to the Scry.Cards.random function.

v4.0.2 (February 11th, 2023)

  • Wrote a lil polyfill for node:events when it doesn't exist, should make the module work in browser with no fancy rollup type stuff needed.

v4.0.1

Was a bit too fast on the draw with the 4.0.0 release, did not build it locally and just ended up publishing 3.3.0 as 4.0.0 instead. Whoops.

v4.0.0 (February 5th, 2023)

  • Removed axios dependency in favour of native fetch, thanks to mlavina via #59. This requires at least node v18, hence a major bump!

v3.3.0 (February 2nd, 2023)

  • Added support for Scryfall's new "migrations" endpoint. Note that this endpoint is still in beta, so something might break in the future with it.
  • Added support for querying cards by their Cardmarket IDs.
  • Bumped axios dependency up to v1.3.1. Updates and fixes provided by furgin — thank you!
  • Added missing svg_uri field to CardSymbol interface.
  • Updated compressed_size field to size.
  • Both strings and numbers are now accepted in all places requiring a collector number.
  • Fixed tests. (Scryfall's returned card images uri changed.)

v3.2.1 (September 3rd, 2022)

  • Undid that last fix and replaced with one that actually works how it was originally intended.

v3.2.0 (September 3rd, 2022)

  • Removed "homepage links" support as the API doesn't work for them anymore.
  • Fixed .cancelAfterPage().waitForAll() never resolving.

v3.1.0 (March 18th, 2022)

v3.0.0 (February 22nd, 2022)

Breaking Changes

  • Scry.error() has been removed. When queries error, it now rejects the promise they return rather than returning undefined or { data: [], not_found: [] }

Other Changes

v2.1.1 (January 5th, 2020)

v2.1.0 (December 22nd, 2020)

v2.0.0 (June 21st, 2020)

  • Removed Cards.all method as Scryfall has removed the endpoint from their API.
  • Cards.search now supports passing a page number in place of SearchOptions.
  • Added better support for downloading bulk data from Scryfall, accessible via Scry.BulkData
    • Misc.bulkData() is now BulkData.definitions()
    • Added BulkData.definitionById, BulkData.definitionByType.
    • Added BulkData.downloadById, BulkData.downloadByType, both of which take a lastDownload time and, if the bulk data has been updated since the last download, return a Stream for the download to be consumed as you see fit.

Note: In cases where you have a proper reason for paginating through every single card in Scryfall's database, such as displaying a paginated list to the user of your application, you can use any query which matches all cards, such as Cards.search("year>0"). Please respect Scryfall and only do this if you need to, though. If you just need to download all the cards, use the new and improved bulk data support!

v1.6.4 (May 11th, 2020)

  • Added not_found array property to MagicEmitter.waitForAll() return. Added MagicEmitter.notFound(). Based on a PR by aSlug

v1.6.3 (March 30th, 2020)

  • Changed set_type on Card objects to the type of Set objects' set_type.

v1.6.2 (March 29th, 2020)

  • Added some missing properties to the Card object.

v1.6.1 (March 7th, 2020)

v1.6.0 (March 2nd, 2020)

v1.5.1 (May 31st, 2019)

  • Updated axios to fix a security issue.

v1.5.0 (March 23rd, 2019)

  • Thanks to a contribution from somkun, the Scryfall SDK now uses Axios instead of Request Promise
  • Added Scry.setRetry
  • There was heavy refactoring in this update. You may notice some d.ts changes, most of that is updating interfaces as per the Scryfall documentation and not exporting some interfaces/enums.

v1.4.0 (February 14th, 2019)

v1.3.3 (November 8th, 2018)

  • Fixed RelatedUris and PurchaseUris throwing errors in some configurations.

v1.3.2 (September 16th, 2018)

v1.3.1 (August 10th, 2018)

v1.3.0 (July 31st, 2018)

v1.2.1 (June 14th, 2018)

Fixed waitForAll throwing an uncatchable promise rejection error.

v1.2.0 (May 30th, 2018)

Misc updates. Now using a Typescript Gulp file and Gulp@4.0

New features:

v1.1.0 (March 16th, 2018)

New features:

v1.0.2 (March 16th, 2018)

Fixed an issue that caused the first page of results to be duplicated. How did I miss that for so long?

v1.0.1 (November 20th, 2017)

Fixed broken tests, some code cleanup

v1.0.0 (August 26th, 2017)

Initial release