The /table
endpoint allows you to submit table queries and receive the results.
Overview
Endpoint | https://stat-xplore.dwp.gov.uk/webapi/rest/v1/table |
---|---|
HTTP Method | POST |
Request Headers
Accept-Language |
The language that labels will be returned in (setting this is equivalent to changing the dataset and user interface language in Stat-Xplore). | Optional. If not set, the server default language will be used. |
---|---|---|
APIKey |
The API Key to use to authenticate this request. You can obtain your API key from the Account page in Stat-Xplore. | Required in all requests. |
Content-Type |
Must be set to application/json . |
Required in all requests. |
---|
Request Body
The body of the request contains your query. It must be in JSON format and contain the following objects:
Object | Description | Example |
---|---|---|
database |
The ID of the dataset you want to query. | "database" : "str:database:PIP_Monthly" |
measures |
An array of IDs of all the variables you want to return. | "measures" : [ "str:count:PIP_Monthly:V_F_PIP_MONTHLY" ] |
recodes |
(Optional). An object containing recodes for any of the fields specified in the request. Use this if you:
For each field you want to recode, you need to include the field's ID as a key and within that object set a The example on the right shows a recode for the Region field. In this example the API will return only two field values for the Region field: one will be for the London region alone (code: E12000007), and the second will be the combined total of North East (code: E12000001) and North West (code: E12000002) combined into a single value. To request a total for a field, include the field's ID as a key and within that object set the |
"recodes" : { "str:field:PIP_Monthly:V_F_PIP_MONTHLY:LA_code" : { "map" : [ [ "str:value:PIP_Monthly:V_F_PIP_MONTHLY:LA_code:V_C_GEOG05_REGION_TO_COUNTRY:E12000007" ], [ "str:value:PIP_Monthly:V_F_PIP_MONTHLY:LA_code:V_C_GEOG05_REGION_TO_COUNTRY:E12000001", "str:value:PIP_Monthly:V_F_PIP_MONTHLY:LA_code:V_C_GEOG05_REGION_TO_COUNTRY:E12000002" ] ], "total" : true }, "str:field:PIP_Monthly:V_F_PIP_MONTHLY:SEX" : { "total" : false } }
|
dimensions |
An array of IDs of the fields in each dimension (e.g., row, column, wafer) of your table. Each dimension must be specified as an array: to combine fields within an axis, simply specify multiple field IDs within that array. |
"dimensions" : [ [ "str:field:PIP_Monthly:V_F_PIP_MONTHLY:LA_code" ], [ "str:field:PIP_Monthly:V_F_PIP_MONTHLY:SEX" ] ] |
As shown here, all IDs specified in the request need to be in the ID format that is returned by the /schema
endpoint.
The following is an example of a request to the API to obtain a table of Region by Gender from the Personal Independence Payments dataset:
{ "database" : "str:database:PIP_Monthly", "measures" : [ "str:count:PIP_Monthly:V_F_PIP_MONTHLY" ], "recodes" : { "str:field:PIP_Monthly:V_F_PIP_MONTHLY:LA_code" : { "map" : [ [ "str:value:PIP_Monthly:V_F_PIP_MONTHLY:LA_code:V_C_GEOG05_REGION_to_COUNTRY:E12000001" ], [ "str:value:PIP_Monthly:V_F_PIP_MONTHLY:LA_code:V_C_GEOG05_REGION_to_COUNTRY:E12000002" ] ], "total" : true }, "str:field:PIP_Monthly:V_F_PIP_MONTHLY:SEX" : { "total" : true } }, "dimensions" : [ [ "str:field:PIP_Monthly:V_F_PIP_MONTHLY:LA_code" ], [ "str:field:PIP_Monthly:V_F_PIP_MONTHLY:SEX" ] ] }
In this example:
- The Region field has been recoded so that only values for North East and North West will be returned.
- No recodes are specified for the Gender field, so all available field values will be returned.
- Totals have been requested for both fields.
Response Body
The response contains the results of your table query. It contains the following objects:
Object | Returns | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
query | The query that was submitted. This object contains the The For example, the above sample query requests a table containing Region and Gender, but only specifies a recode for the Region field. The | ||||||||||||||||
database | Details of the dataset that was queried:
| ||||||||||||||||
fields | Details of the fields that were queried:
| ||||||||||||||||
measures | An array containing all the measures (summation options) returned for this query. For each measure, the API returns:
| ||||||||||||||||
cubes | An array containing the results of the query. There will be one item in this array for each measure you requested. Each item specifies the measure, and then provides the values for each cell in the cube for that measure. | ||||||||||||||||
annotationMap | Any annotations that apply to this query. If there are annotations for the dataset or its fields, then the annotation keys and descriptions will be returned in this object. |