The query can thus be defined in the URL itself.
Read more about PxWebApi v2 in StatBank PxWebApi user guide.
How to replace a ready-made dataset with a new query in PxWebApi v2
The most commonly used datasets have been translated into new queries (in json-stat2 and CSV format) (XLSX)
If you need to translate other queries, follow this recipe:
- Find the Statbank table that is the source of the figures in the dataset
- Select the variables that you want to include
- At the bottom under "Save" you will find the API query
- Select the desired format and copy the GET URL that appears
- Paste the link as a new http query (GET) in Postman or similar application
- If you did not select all the periods, PxWeb will list in the query exactly the same periods you selected. Then you need to adjust the query to valueCodes[Tid]=from(starttime) or =top(number of newest periods).
- If you want csv format, add outputFormatParams to specify the separator and code/text, for example: separatorsemicolon, usetexts.
- List up the variables in stub, usually with Tid and ContentsCode at the end.
Please note that in the old API, the datasets may have some variables that show code and text, while other variables only show text in the csv format. In PxWebApi v2, you choose this for the entire dataset, i.e. for all variables: UseCodesAndTexts or UseTexts. However, the codes are always included for some variables that are set to show code together with text in PxWeb (especially industry and region).
Please note that PxWebApi v2 only supports version 2 of the json-stat format, while the API with ready-made datasets supported version 1 of json-stat.
Contact statistikkbanken@ssb.no if you have questions about the tables or the API.