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

217
Visualizações
How to get the right API information via JSON using React and Axios

I'm trying to get the Swedish consumer price index (Konsumentprisindex - KPI) from the national statistics website (SCB) via an open API. I'm using React and Axios.

Api: http://api.scb.se/OV0104/v1/doris/en/ssd/PR/PR0101/PR0101A/KPIFastAmed

I don't understand what values in the API will give me the KPI. response.data.variables[1].values[0] only respond the year, but I don't understand how to retrieve the KPI from that specific year.

Thanks in advance, have a great day!

This is my App.js

import React,{useState} from 'react';
import './App.css';
import Axios from 'axios';

function App() {

const [KPI, setKPI] = useState("");

  const getKPI = () => {
    Axios.get("http://api.scb.se/OV0104/v1/doris/en/ssd/PR/PR0101/PR0101A/KPIFastAmed")
    .then((response) => {
      console.log(response)
      setKPI(response.data.title 
        + " " +
        response.data.variables[1].values[0])  
    });
  }

  return (<div><h1>{KPI}</h1><button onClick={getKPI}>M3</button></div>);
}

export default App;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As the Docs says , You need to send POST request with body that looks like this :

{  
"query": [
 {       
 "code": "ContentsCode",
  "selection": {        
    "filter": "item",         
    "values": [          
      "000000KL"         
    ]      
   }    
},    
{      
  "code": "Tid",
   "selection": {        
   "filter": "item",         
   "values":   ["2011"]             
  }    
 }   
],  
"response": {    
  "format": "json"   
 }
}

And the response will be :

{
    "columns": [
        {
            "code": "Tid",
            "text": "year",
            "type": "t"
        },
        {
            "code": "000000KL",
            "text": "Konsumentprisindex (KPI) fastställda årsmedeltal, totalt, 1980=100",
            "type": "c"
        }
    ],
    "comments": [],
    "data": [
        {
            "key": [
                "2011"
            ],
            "values": [
                "311.43"
            ]
        }
    ],
    "metadata": [
        {
            "infofile": "PR0101",
            "updated": "2021-01-13T12:50:00Z",
            "label": "Konsumentprisindex (KPI) fastställda årsmedeltal, totalt, 1980=100 by year and observations",
            "source": "Statistics Sweden"
        }
    ]
}

And you can change the values to get the information of the year you need .

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