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

220
Views
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 answers
Answer question

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 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!