PokemonTCG / pokemon-tcg-api

Pokemon TCG API allows developers to easily consume Pokemon card and set data in JSON format.
61 stars 3 forks source link

Getting duplicate sets in api call #102

Closed RichardHpa closed 1 year ago

RichardHpa commented 1 year ago

I am using the typescript sdk and making a request to get sets like bellow.

  const sets = PokemonTCG.findSetsByQueries({
    pageSize: 12,
    // comes from a param
    orderBy: "releaseDate",
    page: page,
  })

I have an infinite scroll function added that makes a new request by bumping the page number up and then adding the next set of results to the components state. I am then mapping over that data and using the set.id as the key in the map. When I do that though I often get an error saying duplicate keys. It often appears for set.id of ex5. I don't think its anything wrong with my code as all I am doing is changing the page number but sometimes the api still returns data that should of been in the previous request.

You can see the full implementation of it here https://github.com/RichardHpa/pokemon-tgc-collector/blob/feature/sets/app/routes/expansions/index.tsx

jaymarvels commented 1 year ago

If you look at the data source:

https://github.com/PokemonTCG/pokemon-tcg-data/blob/master/sets/en.json

There isn't a duplicate for ex5 (your example) could you just do a sanity check and pull back all sets and see if there is the duplicates as there shouldn't

RichardHpa commented 1 year ago

ok i have managed to replicate the situation. My api call has 3 params. Pagesize with is 8, page which is whatever page you are on, and orderBy which I am setting to releaseDate (i know thats default but just using it as an example)

if you got to these 2 apis calls which technically should be different, they both include ex5

page 3 https://api.pokemontcg.io/v2/sets?pageSize=8&page=3&orderBy=releaseDate page 4 https://api.pokemontcg.io/v2/sets?pageSize=8&page=4&orderBy=releaseDate

adback03 commented 1 year ago

This should be fixed.

RichardHpa commented 1 year ago

@adback03 it isnt fixed yet, if you click on those 2 links I have provided above they both still include ex5

RichardHpa commented 1 year ago

@adback03 could you please relook at this as it still isnt fixed, check the api links in the comment above. If that is expected behaviour then also please let me know