MagicTheGathering / mtg-sdk-javascript

Magic: The Gathering SDK - Javascript
MIT License
285 stars 61 forks source link

Question: Can I query multiple CMCs? #28

Open rendermouse opened 2 years ago

rendermouse commented 2 years ago

How do I fetch cards filtering by multiple cmc? If I do this: mtg.card.where({set: 'VOW', cmc: '2|3'}) I get a Bad Request error, even though the MTG.io API supports OR operations.

I can do an OR search on colors just fine (red|black), but cmc seems to fail.

raineorshine commented 2 years ago

Hmmm good question. I read the documentation and the pipe character is the correct way to specify an "or" operation. The error you are seeing is coming directly from the API, even when the pipe is URI encoded:

https://api.magicthegathering.io/v1/cards?set=VOW&cmc=2%7C3

I would suggest reaching to someone on the Discord server. If you can find an API url that works, I can make sure it is supported by the Javascript SDK.

rendermouse commented 2 years ago

The only thing I can figure out is that cmc is designated as a number in the MTG.io docs, which means the API would reject an OR string. I can work around it by filtering by cmc in the UI, but I don't like loading the extra data and then filtering so much of it out if you want to fetch 1-drop Crimson Vow cards.

raineorshine commented 2 years ago

I think that's a good hypothesis. String fields work fine:

https://api.magicthegathering.io/v1/cards?name=Virtuous|Vicious