MagicTheGathering/mtg-sdk-dotnet

get all card sets

Closed this issue · 13 comments

Hi

I have the same problem as here #74
but I don't know what to change in the code to go beyond the 500 sets.
Can you give a small code example and update the code example on github on how to get all card sets?

thx

I believe that the most recent release version added new Set query parameters, Page and PageSize.

So, you essentially query via pages similar to how you would with the card service:

var result = await setService
    .Where(s => s.Page, 3)
    .Where(s => s.PageSize, 10)
    .AllAsync();

Getting all of the card sets would involve calling the above code multiple times, with the s.Page argument being changed.

Another option would be to just specify the s.PageSize to a higher value:

var result = await setService
    .Where(s => s.PageSize, 550)
    .AllAsync();

Although with this option, I haven't tested if there is a max limit to what the s.PageSize value can be.

Hopefully this helps.

Hi

Thanks for your help! I have 2 questions about this.

  • Is it possible the main developer can tell me what the maximum value of s.PageSize can be?

I now use the second code option but I get strange results when the s.PageSize value is high.

For example this code gives me 606 card sets, when using value 1000 for s.PageSize.

var AllCardSets = await setService.Where(s => s.PageSize, 1000).AllAsync()

But when using value 1500 or more, I get 500 card sets again (which is the same as the original bug).
So how do we know what value to choose to get ALL card sets since the card sets expand in the future too (and therefore also the value of s.PageSize)?

  • Is it correct the API only has 606 card sets?
    Because when comparing to Scryfall, there are 743 card sets in the entire Magic history.
    https://scryfall.com/sets
    So more then 100 card sets are missing?

Hello, It's important to remember that this library is just a wrapper around the Web API. So with that said it makes the rules lol. I would check out the API documentation to see if there is anything on making a call with that many.

With that said I would avoid just setting a large PageSize and go with the first example @billybimbob gave. This is the proper way to get all sets. You should be able to look at the PageInfo object in the result for the total number of pages and the total amount of sets.

image

Hi

While the first example of billybimbob returns the card sets immediately, this example never ends here.
If I print the pageResult.PagingInfo.TotalPages in the for loop, I get 61 and it's looping forever. I waited over 15 minutes and it seems to never stop.

Any idea what's wrong? I'm a beginner using this SDK.

61 total requests will take a while to all complete. I would recommend increasing the PageSize value to a higher value, like 100. This should reduce the total amount of requests and also complete a lot sooner

I tried this but then I get a null pointer on pageResult and it crash
I'm totally stuck.

Sorry I should have clarified PageSize = 10 was just for the example and is way too small. I'm not sure what you mean by null pointer. Are you saying that pageResult is null? You might want to save the original values from the first call into it's own variables ie. int totalPages and int pageSize

Can you adjust the example so it fully works with the correct PageSize?
I don't know what to do and don't understand the null pointer. Run this example to see it yourself.

Sorry the null pointer was a bug in my code somewhere else.

I now tried to compare 2 ways of doing it, and still I don't know how to get the exact correct number of all card sets.

  • method 1:

var AllCardSets = setService.Where(s => s.PageSize, 1000).AllAsync();

606 card sets found

  • method 2 (I used PageSize value 100):

var AllCardSets = await setService.Where(s => s.Page, 1).Where(s => s.PageSize, 100).AllAsync();
Debug.WriteLine("pages: " + AllCardSets.PagingInfo.TotalPages);
Debug.WriteLine("card sets: " + AllCardSets.Value.Count);

for (int i = 2; i < AllCardSets.PagingInfo.TotalPages; i++)
{
AllCardSets = await setService.Where(s => s.Page, i).Where(s => s.PageSize, AllCardSets.PagingInfo.PageSize).AllAsync();
Debug.WriteLine("pages: " + AllCardSets.PagingInfo.TotalPages);
Debug.WriteLine("card sets: " + AllCardSets.Value.Count);
}

600 card sets found.

This produces the output:

pages: 7 card sets: 100 pages: 7 card sets: 100 pages: 7 card sets: 100 pages: 7 card sets: 100 pages: 7 card sets: 100 pages: 7 card sets: 100

Where are the 6 missing card sets? Or are there even more missing in this method too?

Thanks for the help

you have a typo in the for loop is should be i <= AllCardSets.PagingInfo.TotalPages

Thx! It's working now

Do you have an idea why Scryfall has 743 card sets while this API only has 606?

https://scryfall.com/sets

no idea maybe the web api needs an update or something. Take a look at the website maybe it has some reasoning behind it

The owner of the API also seems not to respond. In the past (months ago) I tried to report missing cards but no answer at all :-(