PxWebApi v1 will live on in parallel with the new API for several years to come. Please note that PxWebApi 2.0 beta is not available in the morning between 0500 and 0815 for the time being, and not Saturday and Sunday.
Read about how PxWebApi 2.0 works:
https://github.com/statisticssweden/PxApiSpecs/blob/master/specs.md
Limits, formats and defaults in the API
https://data.ssb.no/api/pxwebapi/v2-beta/config
Navigate in subject overview
https://data.ssb.no/api/pxwebapi/v2-beta/navigation?lang=en
Search for a specific text in all tables
https://data.ssb.no/api/pxwebapi/v2-beta/tables?query=restaurant&lang=en
If the hit list goes over several pages, there will be a link to the next and last page at the bottom.
Metadata for a given table (5-digit table number)
https://data.ssb.no/api/pxwebapi/v2-beta/tables/03013/metadata?lang=en&outputformat=json-stat2
Data (section) for a table
https://data.ssb.no/api/pxwebapi/v2-beta/tables/03013/data?lang=en
Please note that this provides a section of data (start table in PxWeb), not all data. To get all data, the query must include the various "dimensions" and ask for all values (=*).
Asterisk as truncation character
Tid= 2020* will in table 03013 give all months in 2020:
Can skip the output format if you want the default output format:
Asterisk to retrieve all consumption groups
Question mark to indicate the number of characters in the code of a value
valueCodes[Konsumgrp]=?? will in table 03013 give all consumption groups with a two-digit code:
Top or bottom to specify the x first or last values in a list
valueCodes[Tid]=top(3) gives the three most recent months in the table:
From or to to specify the start value or end value from a list
valueCodes [Tid]=from(2021M01) gives all months from and including 2021M01:
Range to specify the start and end value from a list
valueCodes[Konsumgrp]=[range(01.1,02.2)] gives all consumption groups from code 01.1 up to and including code 02.2:
You can only enter valid (existing) values as start and end.
Elimination (leave out a variable from the query)
Omit (eliminate) here age, sex and region, and get the total figures instead:
Please note that time [Tid] cannot be eliminated in this API.
Limit tovalues in a given valueset
Retrieves all single values in the value set vs_Fylker:
Limit to values in a given grouping
Retrieves all aggregated values from the grouping agg_KommSummer in table 01222:
Retrieves all single values in grouping agg_FylkerGjeldende in table 13536:
Both http GET and http POST
You can choose to use GET or POST calls in this new API. There is a limit of around 2500 characters in the URL for GET calls. You will get an error message if you try with a URL that exceeds this. Then you can either use POST instead, or you can reformulate the query, for example using truncation, "from" or "range".
New metadata
The new API offers more metadata than before.
If there are several valuesets og groupings attached to a variable, these are listed under “codeLists”.
Under "extension" you will find, among other things, "contents", which shows the first part of the table title that is generated in PxWeb when the user selects variables themselves.
Known errors
Under endpoint metadata, links containing codeLists do not work.
"subject-code" shows constant "al" and "subject-area" shows "Work and pay". Of course, this is not true for all tables.
In progress
The API is under development. Among other things, endpoint data will be changed, and the default format for metadata will be changed to json-stat2.
PxWeb currently only shows POST requests for PxWebApi 1, but we will later also show GET requests for PxWebApi 2.
Contact
Contact statistikkbanken@ssb.no if you have any questions about the tables or the API.
It is also possible to provide feedback on GitHub: