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;
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 .