Table - Open Data API
The /table
endpoint allows you to submit table queries and receive the results.
Overview
Endpoint | http://<server>/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 SuperWEB2). | 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 Preferences page in SuperWEB2. | 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:bank" |
measures | An array of IDs of all the measures (summation options) you want to return. | "measures" : [ "str:count:bank:F_Customer" ] |
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 Marital Status field. In this example the API will return only two field values for the Marital Status field: one will be for the status Married (code: M), and the second will be the total of Single (code: S) and Divorced (code: D) 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 You can omit the If you choose to include the If you set | "recodes" : { "str:field:bank:F_Customer:Marital_Status" : { "map" : [ [ "str:value:bank:F_Customer:Marital_Status:C_Marital_Status:M" ], [ "str:value:bank:F_Customer:Marital_Status:C_Marital_Status:S", "str:value:bank:F_Customer:Marital_Status:C_Marital_Status:D" ] ], "total" : true }, "str:field:bank:F_Customer:Gender" : { "total" : true } }
|
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 (this will concatenate the fields on that axis). | "dimensions" : [ [ "str:field:bank:F_Customer:Marital_Status" ], [ "str:field:bank:F_Customer:Gender" ] ] |
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 Marital Status by Gender from the Retail Banking dataset:
{
"database" : "str:database:bank",
"measures" : [
"str:count:bank:F_Customer"
],
"recodes" : {
"str:field:bank:F_Customer:Marital_Status" : {
"map" : [
[
"str:value:bank:F_Customer:Marital_Status:C_Marital_Status:S"
],
[
"str:value:bank:F_Customer:Marital_Status:C_Marital_Status:M"
]
],
"total" : true
},
"str:field:bank:F_Customer:Gender" : {
"total" : true
}
},
"dimensions" :
[
[
"str:field:bank:F_Customer:Marital_Status"
],
[
"str:field:bank:F_Customer:Gender"
]
]
}
In this example:
- The Marital Status field has been recoded so that only values for Single and Married 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 Headers
X-RateLimit | The rate limit configured for this server. By default, this is set to 100. |
---|---|
X-RateLimit-Remaining | The number of requests remaining for the current rate limiting period. If this value drops to 0 then you will not be able to submit any further requests using this API key until the limit resets. |
X-RateLimit-Reset | The time when the rate limit will next be reset. This is expressed as a UNIX timestamp in milliseconds (the number of milliseconds since January 1st 1970). |
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 Marital Status and Gender, but only specifies a recode for the Marital Status 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. |
For example, the following response is returned for the example query shown in the Request Body section above:
{
"query": {
"database": "str:database:bank",
"measures": [
"str:count:bank:F_Customer"
],
"recodes": {
"str:field:bank:F_Customer:Gender": {
"map": [
[
"str:value:bank:F_Customer:Gender:C_Gender:M"
],
[
"str:value:bank:F_Customer:Gender:C_Gender:F"
],
[
"str:value:bank:F_Customer:Gender:C_Gender:U"
],
[
"str:value:bank:F_Customer:Gender:C_Gender:-1"
]
],
"total": true
},
"str:field:bank:F_Customer:Marital_Status": {
"map": [
[
"str:value:bank:F_Customer:Marital_Status:C_Marital_Status:S"
],
[
"str:value:bank:F_Customer:Marital_Status:C_Marital_Status:M"
]
],
"total": true
}
},
"dimensions": [
[
"str:field:bank:F_Customer:Marital_Status"
],
[
"str:field:bank:F_Customer:Gender"
]
]
},
"database": {
"id": "bank",
"annotationKeys": []
},
"fields": [
{
"uri": "str:field:bank:F_Customer:Marital_Status",
"label": "Marital Status",
"items": [
{
"type": "RecodeItem",
"labels": [
"Single"
],
"uris": [
"str:value:bank:F_Customer:Marital_Status:C_Marital_Status:S"
]
},
{
"type": "RecodeItem",
"labels": [
"Married"
],
"uris": [
"str:value:bank:F_Customer:Marital_Status:C_Marital_Status:M"
]
},
{
"type": "Total",
"labels": [
"Total"
]
}
]
},
{
"uri": "str:field:bank:F_Customer:Gender",
"label": "Gender",
"items": [
{
"type": "RecodeItem",
"labels": [
"Male"
],
"uris": [
"str:value:bank:F_Customer:Gender:C_Gender:M"
]
},
{
"type": "RecodeItem",
"labels": [
"Female"
],
"uris": [
"str:value:bank:F_Customer:Gender:C_Gender:F"
]
},
{
"type": "RecodeItem",
"labels": [
"Unknown"
],
"uris": [
"str:value:bank:F_Customer:Gender:C_Gender:U"
]
},
{
"type": "RecodeItem",
"labels": [
"Not Applicable"
],
"uris": [
"str:value:bank:F_Customer:Gender:C_Gender:-1"
]
},
{
"type": "Total",
"labels": [
"Total"
]
}
]
}
],
"measures": [
{
"uri": "str:count:bank:F_Customer",
"label": "Customers"
}
],
"cubes": {
"str:count:bank:F_Customer": {
"values": [
[
59144,
53967,
10,
0,
113121
],
[
30323,
43405,
8,
0,
73736
],
[
89467,
97372,
18,
0,
186857
]
],
"precision": 0
}
},
"annotationMap": {}
}
These results are equivalent to generating a table similar to the following in SuperWEB2: