Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
How would you extract this info from this api?

I'm kind of new with express, I'm currently working with thedogapi, I am doing the backend and I need to make a GET to an exact part of the api (the temperaments) that's bringing me a lot of problems, an example of the api is:

    },
"id": 1,
"name": "Affenpinscher",
"bred_for": "Small rodent hunting, lapdog",
"breed_group": "Toy",
"life_span": "10 - 12 years",
"temperament": "Stubborn, Curious, Playful, Adventurous, Active, Fun-loving",
"origin": "Germany, France",
"reference_image_id": "BJa4kxc4X",
"image": {
"id": "BJa4kxc4X",
"width": 1600,
"height": 1199,
"url": "https://cdn2.thedogapi.com/images/BJa4kxc4X.jpg"
}

As you can see, my problem it's that it is only a string with words inside, the thing here would be extracting only the temperaments so I can save them on my database once extracted, but the question is, how could I do that? I have been trying a few things, but doesn't seems to work... A code I was trying was

const getTemp = await Temperament.findAll()
if (getTemp.length === 0){
  const apiAxios = await axios.get(`https://api.thedogapi.com/v1/breeds?api_key=${API_KEY}`)
  
  const infoToGet = await apiAxios.data?.map(el => {
    console.log(el.temperament?.split(",").map(el => el.trim()).toString())
    return {
      temperament: [el.temperament]?.join().split(",").map(el => el.trim()).toString()
    }
  })
  const dbSave = await 

Temperament.bulkCreate(infoToGet)
}

I totally discarded that code since it wasn't achieven what I wanted, but the part of the temperaments was kinda working according to the console log, but still wasn't working, so then I received kind of a reference for help, but this wouldn't make it since it's using array methods... I'll show you (that code bellow should work if it was an array...)

router.get("/temperaments", async (req, res) => {
    const temperamentsApi = await axios.get(`https://api.thedogapi.com/v1/breeds?api_key=${API_KEY}`)
    const temperaments = temperamentsApi.data.map( el => el.temperament)
    const tempEach = temperaments.map(el => {
        for (let i = 0; i < el.length; i++) return el[i]})
        console.log(tempEach)
    tempEach.forEach(el => {
        Temperament.findOrCreate({
            where: { temperament: el }
        })
    })

    const allTemperaments = await Temperament.findAll()
    res.send(allTemperaments)
})

how would you make this last thing work on the TEMPERAMENT part alone? sorry if it was kinda long, I'm new in all this, and I'm truly stuck here :s

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

According to the API reference:

https://docs.thedogapi.com/api-reference/breeds/breeds-list

I give you an example for your reference, I refer to your code, the variable temperamentsApi stores the API result, so the extraction code should be as below.

let result=[];
temperamentsApi.data.forEach(datum=>{
    result.push(datum.temperament);
});
console.log(result);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda