
Magic: The Gathering API - kressaty
http://mtgapi.com/
======
tlrobinson
Fun fact: mtgox (the Bitcoin exchange) originally stood for "Magic: The
Gathering Online Exchange" and was a site for buying/selling "Magic: The
Gathering" cards.

~~~
nwh
I wish people would stop repeating this.

The domain was just reused, the site was never actually sold cards.

The current owner has absolutely nothing to do with the original domain name.

~~~
weego
He didn't say anything about the current owner, only the original intent of
the name. Even then, I think your reaction might be a little over the top.

~~~
nwh
The insinuation is that the current site is somehow tainted by it's use back
in 2007, but as far as I can find [1] it was never anything but a "coming
soon"page.

It's fairly common to ridicule it's current use in the Bitcoin world by
associating the currency exchange with playing cards.

[1]:
[http://web.archive.org/web/20070817170606/http://mtgox.com/g...](http://web.archive.org/web/20070817170606/http://mtgox.com/gwt/mtgox.php)

~~~
Ntrails
Why would anyone consider mtg something worthy of ridicule?

~~~
zeckalpha
The same reason they consider bitcoin worthy of ridicule.

------
throw_away
Another recently popular game which may be of interest to HN is Android:
Netrunner. It is an asymmetrical game wherein one player is the corporation
who has a set of servers and is trying to advance adgenda cards while the
other player is the runner, who is trying to hack into the corporation's
servers with a set of programs, hardware and other resources. Like Magic,
there is the actual game play, but then also the meta game play of picking
cards to customize decks to play each role.

It shares the same designer as Magic (Richard Garfield), but is a Living Card
Game rather than a Collectable Card Game. The difference being that in Magic
you spend tons of money hoping for the random drop of particular rare cards or
buy them individually from dealers. In A:NR, they release a new "data pack"
about once a month and then have mini-expansions maybe once a year. It's more
like a subscription model, but the net effect is that every card is worth the
same as every other card. Still not a cheap hobby, but capped, at least (maybe
about $175 to buy every card ever made up to today).

Anyways, someone built a RESTy API for it as well:
[http://netrunnercards.info/apidoc/en.html](http://netrunnercards.info/apidoc/en.html)

~~~
endgame
Not only that but the game is completely different to Magic. It comes from an
earlier time, before the idea of "turn cards sideways to show they've been
used" took hold. It has a very different economy and the two sides play
completely differently.

The LCG data-pack model is great for people playing constructed formats, but
it does make drafting more of a challenge. Mature LCGs are also quite
difficult for latecomers to get into, especially if key packs go out of print.

~~~
shardling
> It comes from an earlier time, before the idea of "turn cards sideways to
> show they've been used" took hold.

Netrunner came out 3 years after Magic.

~~~
endgame
I didn't say that it predated magic, I said that it came about before the idea
of turning cards sideways (as "tapping", "kneeling", "exhausting", "rotating")
became an entrenched mechanic.

~~~
mikeurbanski
It really didn't.

M:TG and Netrunner were both designed by Richard Garfield and Netrunner's
design was directly influenced by his experience with M:TG.

Cards in Netrunner aren't tapped because actions in Netrunner are limited by a
player's "clicks", not just their available resources.

It was a design decision.

------
jacques_chester
This gave me a flashback to Mox Perl.

Until I saw Mox Perl, I had _no idea_ that web pages could be dynamically-
generated by computer programs. It truly blew my mind and triggered a year-
long love affair with Perl.

~~~
k__
wat

~~~
_quasimodo
I guess he is talking about this:
[http://everything2.com/title/Mox+Perl](http://everything2.com/title/Mox+Perl)

~~~
k__
Thank you.

------
jpolitz
This is absolutely awesome.

I have a few thoughts right off the bat.

1.

It would be nice to put a Gatherer link in every response, just for browsing
purposes.

2.

Split cards are weirdly reported, as if they are two separate cards. In
Gatherer these are reported with an id and a "part" field:

    
    
      http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=249394&part=Malice
    

It looks like you're only getting the first part. See that Spite//Malice is
missing from

[http://mtgapi.com/api/v1/fetch/search/malice](http://mtgapi.com/api/v1/fetch/search/malice)

But I can search for "spite" and I find:

[http://mtgapi.com/api/v1/fetch/id/249394](http://mtgapi.com/api/v1/fetch/id/249394)

3.

It looks like you're using the Oracle text for every version (for example,
[http://mtgapi.com/api/v1/fetch/id/198](http://mtgapi.com/api/v1/fetch/id/198)
and
[http://mtgapi.com/api/v1/fetch/id/226588](http://mtgapi.com/api/v1/fetch/id/226588)
have the same rules text, though they appeared differently when printed). Is
there any way to get that information? That could be really cool for mining
information about how terminology has changed over time.

~~~
redcrusher
thanks for the feedback! will keep that in mind in the next few days!

------
ghc
Now someone needs to use this to make a passable Magic AI. Shandalar is
ancient at this point, but it's still the best attempt I've seen, and the only
Magic computer game I still play.

~~~
mpd
I'm not sure if you're aware of Forge or not, but it's actively developed and
will probably give you a better game than Shandalar.

[http://www.slightlymagic.net/wiki/Forge](http://www.slightlymagic.net/wiki/Forge)

~~~
ghc
I was not aware of Forge. Thanks! I guess I stopped paying attention about 10
years ago, shortly after WotC killed Apprentice. I figured, based on their
behavior, that they would never let any unlicensed innovative MTG software
come out. I'm glad they proved me wrong.

~~~
mpd
Cockatrice is the successor to Apprentice, and is still around even after a
recent C&D from WotC. The reason the C&Ds come along is because they all tend
to use terms and concepts that WotC owns, like tapping cards.

[http://cockatrice.woogerworks.com](http://cockatrice.woogerworks.com)

------
calhoun137
Ahh Magic cards! The first website I ever made was a magic card trivia page,
oh about 15 years ago. If I had known about this API, I would have used it
back then ;)

By the way, there is an awesome program called lackeyCCG[1] that I use
whenever I feel the need for a quick fix, it's almost like a free version of
magic online. Plus you can use it to test your own CCG's if you ever had the
urge to make one.

[1] [http://www.lackeyccg.com/](http://www.lackeyccg.com/)

~~~
herbig
Cockatrice is another good one: www.woogerworks.com

------
KaoruAoiShiho
Ahh Magic. That's the game that inspired me to build my own TCG engine.

It uses websockets and modern javascript to let anyone create their own
TCG/CCG in the browser. Unlike Lacky or similar all the cards and actions are
automated so there's no work for the player. It's currently in beta.

This is one of the games that have been built on it:

[http://dulst.com/TouhouRSO](http://dulst.com/TouhouRSO)

~~~
MetaCosm
You... what... you built what I considered building (I worked on the OCTGN
project, which has a similar idea [build your own TCG]).

I had no idea this existed, can't wait to check it out (awww... closed source?
Still cool!).

~~~
KaoruAoiShiho
Thanks, I wanted to build a really really easy engine that truly anyone can
use, not just developers. This is the first time I've heard of OCTGN too.
Checking it out.

------
davidpodolsky
This is very nicely done. Wish this was available when I was developing
CardSplice as it would have saved me some time.

Shameless plug for CardSplice[1] since hacker news is talking about MTG. I had
a ton of fun developing this awesome app that lets you quickly feed Magic
Cards behind your mobile and uses some advanced image processing and OCR to
detect the cards and upload the list into the cloud. Amazing for draft deck
building and organizing.

Anyways, thanks for the MTG web service.

[1] [http://www.CardSplice.com](http://www.CardSplice.com)

------
dsirijus
A slight OT anecdotal - most of the best MtG players I personally knew are now
stock brokers.

The game itself, meta-game and the entire ecosystem around it taught me a lot
about value, perceived value, sales, psychology... I don't regret any of the
thousands dollars spent on it more than a decade ago.

~~~
monkeyspaw
Zero sum games, taking prized possessions from your friends... you can do what
you will.

I don't regret any of my money spent on my MTG cards, but not because it
taught me skills to become a stock broker.

~~~
sliverstorm
If dsirijus played at a higher level, his discussion of value is probably more
about the value of a card in play, rather than its street price...

------
mproud
I put together a json file of all cards, at least up until May of 2013. It’s
not a perfect structure, but it’s close.

[https://github.com/ancestral/Verse/tree/master/json](https://github.com/ancestral/Verse/tree/master/json)

(The Github project itself is many things, and very experimental, but hopes
to, one day, achieve the Holy Grail of being able to enforce rules through
NLP. Yeah, I’m holding my breath too.)

------
jaryd
This looks great! I would be interested in talking to the creator about making
a plugin based on this for DuckDuckGo if they're around and so inclined.

~~~
redcrusher
Jaryd: email if mtgpdb@gmail.com if you would like to get ahold of me. reply

------
mullingitover
Wait, so how do I use this to buy and sell bitcoins?

~~~
eru
Why bother with bitcoins? Magic cards are much better currency.

~~~
loupeabody
No joke, I wasn't aware of how much value there is in MTG until a friend of
mine put down $6000 investing in a bunch of cards. Then again, I don't know
all that much about the game, but you can see that the market for cards on
eBay is really active.

~~~
eru
Some of my friends made good money playing the market: They bought during the
summer drought and sold just after Christmas, when the kids had gotten money
as presents.

------
mikeurbanski
Unfortunately, and I say this from excruciating experience, this isn't a
complete/accurate representation of all M:TG cards.

I spent the summer of 2011 scraping Gather to build out a product catalog and
API for a start up that didn't start. I really wish that I had taken the time
to put the data out as a torrent.

"Magic: The API" doesn't appear to support:

* Multi-faceted cards such as "Fire // Ice"([http://gatherer.wizards.com/Pages/Card/Details.aspx?multiver...](http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=292753&part=Ice))

Both return the data for the "Fire" facet, but with different artists:
[http://mtgapi.com/api/v1/fetch/id/27165](http://mtgapi.com/api/v1/fetch/id/27165)
&
[http://mtgapi.com/api/v1/fetch/id/27166](http://mtgapi.com/api/v1/fetch/id/27166)

* Double sided cards such as "Student of Elements" ([http://gatherer.wizards.com/Pages/Card/Details.aspx?multiver...](http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=78691))

Only shows data for "Tobita, Master of Winds":
[http://mtgapi.com/api/v1/fetch/id/78691](http://mtgapi.com/api/v1/fetch/id/78691)

* Double cards such as B.F.M ([http://gatherer.wizards.com/Pages/Card/Details.aspx?multiver...](http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=9844))

Only shows 1/2 of the cards:
[http://mtgapi.com/api/v1/fetch/id/9844](http://mtgapi.com/api/v1/fetch/id/9844)

* Multi-sided cards such as "Cloistered Youth // Unholy Fiend" ([http://gatherer.wizards.com/Pages/Card/Details.aspx?multiver...](http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=221212))

Only shows the "Unholy Fiend" data:
[http://mtgapi.com/api/v1/fetch/id/221212](http://mtgapi.com/api/v1/fetch/id/221212)

M:TG has 20 years of strangeness to take into account when creating a data
model... And Gatherer has its own issues. For example, the way symbols are
represented in card text is inconsistent. (e.g. The tap symbol can be
represented as both "ocT" and "{T}", and the representations for mana symbols
have evolved inconsistently as well.)

Wizards of the Coast are the only ones who can build this API legally. They
hold the copyright on all of the data related to M:TG and I truly wish that
they would open up it up so that we, as a people, wouldn't have to spend
hundreds of hours recreating the wheel. Poorly. [0]

Fortunately, I stopped what I was doing and started on a board gaming "thingy"
with friends instead:
[http://www.shutupandsitdown.com/](http://www.shutupandsitdown.com/)

[0]: That isn't to say that the mtgapi.com guys/gals did a shoddy job. It's
just a big task that WotC should be forward looking enough to do themselves.

While I have WotC on the line... Why wasn't the D&D 5th Edition SRD hosted on
GitHub during development?

~~~
niels_bom
I think [http://mtgjson.com/](http://mtgjson.com/) does it better.

~~~
joefritz
Wow, just looking at the example card on that makes me realize how ridiculous
MTG has gotten in terms of powerful cards. Each edition seems to get closer to
a "tap to win game" card.

~~~
Slackwise
Exact opposite, actually.

The dev team learned their lesson from the earlier days[1] and do strict
evaluations of cards and interactions before releasing them. The most popular
format, "Standard", is played with the last 2 "blocks" (3 sets of card
"sets"), and 1 "Core Set". So basically the last 1.5—2 years worth of cards.
Those interactions are studied carefully before being released. Very
infrequently do you run into something truly overpowered and needing to be
banned from the competitive scene.

Not to mention, in the most basic sense, cards like Counterspell[2] will
probably never be printed in a Standard playable set, but cards like Cancel[3]
will. One being too cheap to cast and being almost game breaking, while the
other has its power balanced just right for the cost.

[1]:
[http://www.wizards.com/magic/magazine/article.aspx?x=mtg/dai...](http://www.wizards.com/magic/magazine/article.aspx?x=mtg/daily/ld/259)

[2]:
[http://magiccards.info/jvc/en/24.html](http://magiccards.info/jvc/en/24.html)

[3]:
[http://magiccards.info/m14/en/45.html](http://magiccards.info/m14/en/45.html)

~~~
joefritz
Thanks. That "Dealing with Power Creep" article is a good read.

~~~
Slackwise
You're welcome. Glad I could clear that up.

If you haven't played in a while, you should check it out again. There's a
game[1] now for Steam/Xbox/PS3/Android/iOS to get you back into the swing of
things and show you many of the current cards.

[1]:
[https://www.wizards.com/magic/digital/duelsoftheplaneswalker...](https://www.wizards.com/magic/digital/duelsoftheplaneswalkers.aspx)

------
chewxy
Do you have permission to pull data from Gatherer? If so, you should also have
the image url in your response. That'd be awesome

------
dfritsch
I'm interested in where the database came from. Is this all manually compiled
or pulled from a general source?

~~~
redcrusher
All source is pulled form the gatherer. Public Information

~~~
arkem
It's a cool API, I like it.

Just be careful because Wizards of the Coast might disagree with you about
what is and isn't public information. Especially when you are showing the
rating and number of votes and rating straight from Gatherer.

------
laurent123456
There are two "Card by ID" endpoints, I believe the second one should be "Card
by name" or possibly "Search card by name".

------
acbart
Part of my research is to semi-automatically generate client libraries for web
APIs. For funsies, I made this site a definition and ran it through, producing
bindings in Racket, Python, and Java.

They won't be 100% correct, but they'll probably work okay.
[https://github.com/RealTimeWeb/MagicTheGatheringService](https://github.com/RealTimeWeb/MagicTheGatheringService)

------
titusjohnson
Are you planning anything beyond multiverse ID and text search? I usually need
to filter by many attributes. Specifically searching in the flavor text,
filtering by format legality, card color, converted mana cost, etc.

Gatherer offers all of these abilities but not in an easy to use API. Even if
you query gatherer programmatically you're still stuck scraping the page to
get the data.

~~~
redcrusher
it is coming :) no worries stay tuned

------
fallenrayne
It looks really good but there is a little bit of a problem with your data
structure. Technically rarity, flavor text, number, and artist can all be
unique per set. You would be better off including that information in your
"prints" sub-array with each set.

The big one with rarity is Serra Angel and Hypnotic Spectre as both of those
have switched between uncommon and rare, as well as the original Planeswalkers
were just rare in Lorwyn, not mythic as that rarity did not exist at that
time.

Another suggestion is to remove the empty fields. It doesn't really matter too
much normally, but it could be a slight boost in performance for mobile apps
taking advantage of this API as they would essentially be pulling down less
data, especially if it is a multi-card search. (100 bytes isn't too much for 1
card, but 100 cards suddenly makes that 9.7kb of extra data that isn't
necessary.)

Looks really great though, very responsive.

------
zephyrfalcon
For what it's worth, I have related projects on Github (although they haven't
been updated in a while):

[https://github.com/zephyrfalcon/magicripper2](https://github.com/zephyrfalcon/magicripper2)
(to scrape cards from Gatherer)

[https://github.com/zephyrfalcon/magicquery](https://github.com/zephyrfalcon/magicquery)
(to query the card database)

I also made a set of files (not on Github (yet)) that indicate a card's
keywords and other properties (e.g. flying, protection, split card, etc etc).
I found it very hard (read: ~impossible) to extract this kind of info
_reliably_ from the card text.

------
bthomas
Naive legal question - is this API considered copyright infringement? Could
they charge for it?

Similarly, are you allowed to create an endpoint for "products for sale at
Whole Foods" assuming you collect the data legally?

~~~
nwh
I don't think it is in Australia at least. Simply collecting such data and
making it available isn't illegal; only creative works are under copyright.
We've had cases with the phone book being reproduced, and this understanding
is apparently correct.

~~~
kybernetikos
These sites go beyond lists of facts though.

Pretty sure that the text/flavour will be under copyright. The names might
well be too.

------
Everlag
Dang. A nice looking system that does exactly what I was hoping to do with a
project of mine that lost my interest.....

Oh well. I appreciate the whole api but what I would really enjoy is the
source to where the database is acquired from. I presume it is gatherer but
could be wrong because there is at least another site that could be scraped.
That or they are scraping a storefront which would be interesting and
efficient.

And does it handle double sided cards? That's the thing that buggered my
scrapping to the point of annoyance. Damn Innistrad and it's double sided
creatures!

~~~
redcrusher
double sided cards are seen as separate crds at this point . It is a point for
improvement though!

~~~
Everlag
I wish you luck, they are painful unless you feel like trying to parse card
text. At that point you might as well write a bot that plays magic for you....

------
citizenterminal
[http://mtgapi.com/api/v1/fetch/id/4960](http://mtgapi.com/api/v1/fetch/id/4960)
results in a Symfony error trace page.

[edited for typo]

------
LTheobald
You know when you're a geek when you see "Magic: The Gathering" & "API" in the
same sentence and click the link without a second thought.

------
kevinsundar
This is probably the geekiest thing I've seen all week.

------
ismaelc
Hey this is so cool! I documented it in Mashape -
[https://www.mashape.com/community/magic-the-
gathering#!docum...](https://www.mashape.com/community/magic-the-
gathering#!documentation) .

I can transfer it to your official Mashape account. You can continue
documenting it there (on top of managing users, getting analytics, etc). Let
me know! - chris@mashape.com

------
herbig
This would be much more useful if it had prices and card images.

www.mtgprice.com looks like a really good price API, but I haven't tried it
out yet.

------
joshuak
I was thinking it would be cool to make an open source digital trading card
game based on a bitcoin like protocol to insure card existence and
distribution probability. (plus there's the nice circular reference)

I'm sure I'll tinker with this idea eventually, but if anyone would like to
collaborate give me a buzz. I'll spin up a repo and get the ball rolling.

------
philsnow
From one of their examples:

    
    
        [
    	{
    		"id": "202424",
    		"name": "Tundra",
            ...
            }
        ]
    

id# is in the 200000s ? Are these allocated sequentially and contiguously ? If
so, M:tG _really_ got away from me since I stopped paying attention to it.

~~~
ubernostrum
I don't think they are allocated sequentially (and there aren't that many
unique cards/versions). But IIRC Gatherer's using the IDs from the internal
"Multiverse" DB, which also includes all the brainstormed card ideas that
never made it into an actually-released set, which would tend to inflate the
numbers.

 _Edit:_ and they are not allocated sequentially. These two cards have only
ever appeared in the 2014 core set, and have sequential collector numbers in
the set but not sequential IDs:

[http://gatherer.wizards.com/Pages/Card/Details.aspx?multiver...](http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=370750)

[http://gatherer.wizards.com/Pages/Card/Details.aspx?multiver...](http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=370612)

------
brd529
Would be sweet to search by characteristics other than id and name.

Eg all GG creatures with power greater than 3

Nonetheless sweet job!

~~~
ubernostrum
Here:

[http://magiccards.info/search.html](http://magiccards.info/search.html)

(magiccards.info does most of this already, albeit not with a JSON API)

------
niels_bom
Another one: [http://mtgjson.com/](http://mtgjson.com/)

------
aeosynth
I built a draft / sealed simulator, which scrapes Gatherer as part of the
build step. There's thousands of draft results available for data mining.

[https://github.com/aeosynth/draft](https://github.com/aeosynth/draft)

------
john2x
Cool! I did a similar project[1], but I use magiccards.info as a datasource,
so it uses the same (not very intuitive, but quite flexible) query parameters.

[1]: [http://searchthecity.me](http://searchthecity.me)

------
m0skit0
"During the Beta Period, everyone has access to the API. Please test it and
try it out." So you want us to beta-test your stuff for free, but later you
will close it? Not interested, thanks, test it yourself.

------
eru
Now, it would be nice to have some kind of DSL to encode the `text' field.

------
redcrusher
Jaryd: email if mtgpdb@gmail.com if you would like to get ahold of me.

------
rdennis463
as one of contributors to the tutor project, I'd recommend Tutor as way to
programmatically query gatherer on the command line in a way that handles a
lot of the edge cases. I use it on [http://cuesbey.com](http://cuesbey.com) to
import into my own data model.

[https://github.com/davidchambers/tutor](https://github.com/davidchambers/tutor)
and npm install tutor

------
gbraad
... I miss versioning; between Alpha, beta, revised, etc till now many cards
have changed in their use. Nearly 20 years of crud to deal with...

------
enigmabomb
Is this available for the Pokemon cards?

~~~
y2bd
Honestly I'd love just a _Pokedex_ API. It seems like the best right now is
Veekun's work[1]. It just needs to be...API-fied.

Nintendo is very happy to give out C&Ds though, which might explain why such a
thing doesn't already exist.

[1] [https://github.com/veekun/pokedex](https://github.com/veekun/pokedex)

~~~
eevee
I'm actually working on that—hopeful to have something passable out by the
release of X/Y.

~~~
y2bd
Awesome! Are you using Veekun's database, or do you have your own source?

Edit: Wait, you are Veekun! Or at least I think you are, "eevee"'s GitHub
profile links to Veekun's website.

~~~
eevee
veekun is my project, yes :)

------
streblo
I don't suppose you'd provide snapshots of the database that's backing this
API?

------
Abundnce10
I've got a bunch of 3rd and 4th edition cards, how do I find the id of a given
card?

------
eof
any plans to add art?

------
dgwutao
سمَـَّوُوُحخ ̷̴̐خ ̷̴̐خ ̷̴̐خ امارتيخ ̷̴̐خسمَـَّوُوُحخ ̷̴̐خ ̷̴̐خ ̷̴̐خ امارتيخ
̷̴̐خسمَـَّوُوُحخ ̷̴̐خ ̷̴̐خ ̷̴̐خ امارتيخ ̷̴̐خسمَـَّوُوُحخ ̷̴̐خ ̷̴̐خ ̷̴̐خ
امارتيخ ̷̴̐خ

