PxAPI Description
PxAPI Description
PxAPI Description
13
3 URLs................................................................................................................ 3
3.2 API-VERSION.........................................................................................4
3.3 LANGUAGE............................................................................................5
3.4 DATABASE-ID.......................................................................................5
3.5 LEVEL1...LEVELN.................................................................................5
5 Limitations .................................................................................................... 14
6 Logging 14
2020-11-
13
1 Readers’ guide
1.1 What this instruction covers
This manual describes how to use the PxWeb API. The manual is primarily
intended for people who want an introduction on how to use the API. The reader is
not required to have any type of PxWeb experience to understand the content, but it
helps. It also helps to have some knowledge of the HTTP protocol.
Note that the examples in this documentation are fictional and may not work in the
real database of Statistics Sweden.
1.3 Terminology
• HTTP verb – Can be looked upon as HTTP request methods where GET and POST
are the most commonly used.
• HTTP response code – The HTTP protocol uses different response codes to indicate
the response status from the user request. For a list of response codes, see
http://www.w3.org/Protocols/rfc2616/rfc2616- sec10.html
2 Getting started
If you just wish to use the API and want to familiarize yourself with it, you should
read Chapters 3 and 4. If you are interested in enabling the API to expose your
PxWeb database, then you should read all the chapters.
3 URLs
The URL is the way to access the API and it has some similarities to a
RESTful API.
The URLs are constructed with different components:
API-NAME/API-VERSION/LANGUAGE/DATABASE-ID/<LEVELS>/TABLE-ID
http://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0401/BE0401B/BefProgFoddaMedel11
3.1 API-NAME
Browsing the API-NAME will redirect the caller to an information page about the
API or an Http 404 Not Found response.
3.2 API-VERSION
Browsing the /API-NAME/API-VERSION will redirect the user to a page with
information, e.g. terms of usage, features, etc., for the specific version of the API.
Notice that currently you will get an Http 404 Not Found response.
2020-11-
13
3.3 LANGUAGE
Browsing (HTTP verb GET) the /API-NAME/API-VERSION/LANGUAGE will
result in a JSON formatted result page listing the available databases for that
language.
3.4 DATABASE-ID
Browsing (HTTP verb GET) the /API-NAME/API-
VERSION/LANGUAGE/DATABASE-ID will result in a JSON formatted result
page listing the first level nodes of the specified database for the specified language.
For the result format, see 4.1.
3.5 LEVEL1...LEVELN
Browsing (HTTP verb GET) the /API-NAME/API-
VERSION/LANGUAGE/DATABASE-ID/LEVEL1 to /API-NAME/API-
VERSION/LANGUAGE/DATABASE-ID/LEVEL1.../LEVELN will result in a
JSON formatted result page listing the available levels and tables for the specified
databases for that language and that level.
For the result format, see 4.2.
3.6 TABLE-ID
Browsing (HTTP verb GET) the /API-NAME/API-
VERSION/LANGUAGE/DATABASE-ID/LEVEL1.../LEVELN/TABLE-ID will
result in a JSON formatted result page specifying the metadata of the table.
For the result format, see 4.3.
4 JSON formats
4.1 Database result list
This is an array of database objects that has an identity, dbid and a textual
description, text. There are three types of node objects: l, t and h, where l is a
sublevel, t is a table and h is a heading.
Example result of the URL “/doris/en” shows that we have one database.
[{"dbid":"ssd","text":"Statistics Sweden"}]
"text": "Population size by age and sex. Year 2005-2050 2004 - 2050"},
{ "code": "Fodelseland",
"text": "country of birth",
"values":["010","020","030","040","050","060","070"],
"valueTexts":
"Europe excl. EU and Nordic countries","Low HDI excl. Europe", "Medium HDI excl. Europe","High HDI excl.
Europe"], "elimination": true},
{ "code": "Alder",
"text": "age",
"values":
["-14","15","16","17","18","19","20","21","22","23", "24","25","26","27","28","29","30","31","32","33",
"34","35","36","37","38","39","40","41","42","43", "44","45","46","47","48","49+"],
"valueTexts":
["-14 years","15 years","16 years","17 years", "18 years","19 years","20 years","21 years", "22 years","23 years","24
years","25 years",
"elimination": true},
2020-11-
13
"valueTexts":["Births"]},
{ "code": "Tid",
"text": "period",
"values":
["2010","2011","2012","2013","2014","2015","2016", "2017","2018","2019","2020","2021","2022","2023",
"2024","2025","2026","2027","2028","2029","2030", "2031","2032","2033","2034","2035","2036","2037",
"2038","2039","2040","2041","2042","2043","2044", "2045","2046","2047","2048","2049","2050","2051",
"2052","2053","2054","2055","2056","2057","2058", "2059"],
"valueTexts":
["2010","2011","2012","2013","2014","2015","2016", "2017","2018","2019","2020","2021","2022","2023",
"2024","2025","2026","2027","2028","2029","2030", "2031","2032","2033","2034","2035","2036","2037",
"2038","2039","2040","2041","2042","2043","2044", "2045","2046","2047","2048","2049","2050","2051",
"2052","2053","2054","2055","2056","2057","2058", "2059"], "time": true
}
2020-11-
13
• px
• csv
• json
• xlsx
• json-stat
• json-stat2
• sdmx
The format json-stat will return the response as JSON-stat version 1.2 and the format
json-stat2 will return the response as JSON-stat 2.0.
2020-11-
13
{"code":"Alder",
"selection":{"filter":"all", "values":["*"]}},
"response": {"format":"csv"}
}
2020-11-
13
}
Datum Version 14 av 14
2020-11-18 Version
Beteckning 1 (tex Dnr) Beteckning
5 Limitations
The usage of the API can be limited or not. The limitation is based on the
caller IP-address. The way it works is that the caller can make 10 requests
during a time window of 10 seconds (these values can be configured
later). The time period 10 seconds is a sliding time window. If the caller
tries to make more requests than allowed, the API will return a HTTP
429 Too Many Requests response.
6 Logging
The log4net framework is used for the usage logging. The API uses the
api- usage logger to log the data retrievals. Information that is logged is
the IP- address of the caller, the statistical table and the number of
measures that were retrieved.
st