Overview
The GSS StatsBank API requires queries to be sent as JSON objects in POST requests. The query structure defines which variables to retrieve, how to filter them, and what format to return the data in.Complete Query Structure
A complete query consists of two main components:Query Component
Thequery component is a list of variable selections. Each variable selection defines:
- Which variable to filter
- How to filter it (selection method)
- Which values to include
Variable Selection Structure
Parameters
The variable name as shown in the table metadata. Use
build_url() to discover available variable codes for a table.Example values:"WaterDisposal""Geographic_Area""Locality"
Defines how to filter the variable’s values.
The filter method to apply:
"item": Select specific values listed in thevaluesarray"all": Select all available values (use"*"in values)
Array of values to include:
- For
filter = "item": List of specific value strings - For
filter = "all": Single elementlist("*")
Response Component
Theresponse component specifies the format for returned data.
The desired output format. See Response Formats for available options.Common values:
"csv": Comma-separated values"json": JSON format"json-stat": JSON-stat format"json-stat2": JSON-stat2 format
Complete Example
Water Disposal Data Query
This example retrieves water disposal data for specific methods across all geographic areas:Breakdown
First Variable (WaterDisposal):- Uses
filter = "item"to select specific disposal methods - Includes only two values:
- Total households (baseline)
- Sewerage system disposal method
- Uses
filter = "all"to include all regions - Value is
list("*")which is the wildcard selector
- Requests CSV format for easy processing with
read_csv()
Discovering Available Values
To find valid values for thevalues parameter, query the table metadata:
Multiple Variable Selections
You can include as many variable selections as needed:Filter Types
Item Filter
Selects specific values explicitly listed:- Select specific categories
- Limit results to certain regions
- Compare particular values
All Filter
Selects all available values for a variable:- Include every option without listing them
- Retrieve comprehensive datasets
- Avoid hardcoding specific values
Important Notes
All Variables Must Be Selected
You must provide a selection for every variable shown in the table metadata. If a variable is omitted, the API may:- Return an error
- Aggregate the data unexpectedly
- Return incomplete results
Value Matching
Variable values are case-sensitive and must match exactly as shown in the metadata:List Structure
R requires thelist() function for both the values array and the overall structure:
Sending the Query
Attach the query to your request and perform it:Additional Filter Options
The PxWeb API supports additional filter types beyond"item" and "all". Refer to the PxWeb API documentation for:
- Range filters
- Top/bottom filters
- Pattern matching filters
- And more advanced selection methods