Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda