Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

386
Views
PokeAPI Javascript only retrieved name and URL

I want to access to the Pokémon types in the json file.

However, it looks like I can only retrieve name and url, any idea of what am I doing wrong?

const baseUrl = 'https://pokeapi.co/api/v2/pokemon/?limit=3000'
try {
    fetch(baseUrl)
        .then(response => {
            const responseJson = response.json()
            return responseJson
        })
        .then(data => {
            const pokemons = data.results
            pokemons.forEach(pokemon => {
                console.log(pokemon);
            })
        })
        .catch(error => {
            console.error(error)
        })
} catch (error) {
    console.error(error)
}

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Actually, this is how the API is done.

If you want to get more values about pokemons, you need to make another request by the given URL from the first result.

This can be done using another axios call inside the then

const baseUrl = 'https://pokeapi.co/api/v2/pokemon/?limit=1'
try {
    fetch(baseUrl)
        .then(response => {
            const responseJson = response.json()
            return responseJson
        })
        .then(async data => {
            const pokemons = data.results
            for (const pokemon of pokemons){
              pokemon.data = await fetch(pokemon.url).then(res => res.json())
            }
            
            console.log(pokemons)
        })
        .catch(error => {
            console.error(error)
        })
} catch (error) {
    console.error(error)
}

Note that the API is quite slow that's why I would recommand using pagination instead of limit=3000 ad you did.

This can be done using the offsetparameter which is the start of the pagination

For example, ?offset=20&limit=20 will get the 20 pokemons betwenn 20 and 40

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!