Dataset API
Prerequisites:
- Set up API access
- Verify that you have API access and obtain a token via get_token call
Table of contents:
1. Access Admin > System > API Toolkit
2. Configure Dataset Info
2.1. Get Dataset Info
- Item: dataset
- Methods: GET
- Enter ID of the Dataset
- If no ID is provided, the API will return the data of all Datasets
- Enter an API Token
- [Run request]
- The returned object contains Dataset's info
- See Example Response and Fields Description for details
{
"id": "63",
"source_dataset_id": "0",
"source_dataset_filter_id": "0",
"name": "Suppliers Analysis",
"description": "Suppliers Analysis",
"measurement_interval": "3",
"data_storage": "1",
"category": "65",
"data_collection_trigger": "1",
"keep_history": "yes",
"measurement_time_source": "Measurement time command",
"can_historical_instances_be_backfilled": "yes",
"weekly_data_for": "Last day of Week",
"custom_effective_date": "19",
"data_source": "57_sql",
"data_fetch_command": "SELECT * from dataset_61\nWHERE date = :measurement_time",
"omit_partial_periods_ind": "no",
"generate_empty_instance_ind": "skip generation",
"has_access_map_ind": "user has access to all rows",
"instances_to_keep": "1095"
}
Fields Description
2.2. Create Dataset
- Item: dataset
- Methods: POST
- Enter ID of an existing Dataset that you want to use as a model for a new Dataset
- After you enter the Dataset ID, the Request field will display the settings for that Dataset
- Select JSON request and modify the new Dataset's data
- See Example Response and Fields Description for details
- Enter an API Token
- [Run request]
- The returned object contains the new Dataset's info
- Note that the new Dataset's ID is auto-created
2.3. Update Dataset Info
- Item: dataset
- Methods: PUT
- Enter ID of the Dataset you want to update
- Select JSON request and modify the Dataset's data
- See Example Response and Fields Description for details
- Enter an API Token
- [Run request]
2.4. Validate Dataset
- Item: dataset
- Methods: PUT
- Enter ID of the Dataset you want to validate
- Actions: Validate
- Enter an API Token
- [Run request]
- If the Dataset is validated successfully, a corresponding message is returned
2.5. Delete Dataset Data
- Item: dataset
- Methods: PUT
- Enter ID of the Dataset which data you want to delete
- Actions: Delete data
- Select JSON request and enter the time interval for which you want to delete Dataset data in the following format:
{
"call": "delete_data",
"delete_measurements_from": "<Date and time from which the Dataset data is deleted>",
"delete_measurements_through": "<Date and time until which the Dataset data is deleted>"
}
- Enter an API Token
- [Run request]
- If the Dataset data is deleted successfully, a corresponding message is returned
2.6. Get Dataset Access Map (User Map)
- Item: dataset
- Methods: PUT
- Enter ID of the Dataset for which you want to get an Access Map
- Actions: Get Access Map
- Enter an API Token
- [Run request]
- If the Dataset's Access Map data is fetched successfully, its data is returned
2.7. Set Dataset Access Map (User Map)
- Item: dataset
- Methods: PUT
- Enter ID of the Dataset for which you want to get an Access Map
- Actions: Set Access Map
- Select JSON request and provide JSON mapping Dataset parameters with User Map parameters
- Enter an API Token
- [Run request]
- If the Dataset's Access Map data is set successfully, a corresponding message is returned
2.8. Enable Dataset
- Item: dataset
- Methods: PUT
- Enter ID of the Dataset you want to enable
- Actions: Enable
- Enter an API Token
- [Run request]
- If the Dataset is enabled successfully, a corresponding message is returned
2.9. Disable Dataset
- Item: dataset
- Methods: PUT
- Enter ID of the Dataset you want to disable
- Actions: Disable
- Enter an API Token
- [Run request]
- If the Dataset is disabled successfully, a corresponding message is returned
2.10. Update Dataset Data
- Item: dataset
- Methods: PUT
- Enter ID of the Dataset which data you want to update
- This action is an equivalent of [Update Dataset] from the Dataset Editor
- Actions: Update Dataset
- Enter an API Token
- [Run request]
- If the Dataset has been updated successfully, a corresponding message is returned
3. Configure Dataset Data
3.1. Get Dataset Data
- Item: dataset_data
- Methods: GET
- dataset: Enter ID of the Dataset
- view: Optionally, enter ID of the Dataset View
- Optionally, enter measurement_time for which you want to retrieve Dataset data
- Enter an API Token
- [Run request]
- The returned object contains Dataset's info
- See Example Response and Fields Description for details
This example demonstrates an object which represents a single element.
{
"data":
[
{"Name":"User8","Country":"Algeria","Customer ID":"3","Items Purchased":"4","Date":null},
{"Name":"User7","Country":"Algeria","Customer ID":"3","Items Purchased":"10","Date":null},
{"Name":"User10","Country":"Italy","Customer ID":"2","Items Purchased":"12","Date":null},
{"Name":"User6","Country":"Algeria","Customer ID":"4","Items Purchased":"13","Date":null}
]
"metadata":
[
{"name":"Name","type":"text"},
{"name":"Country","type":"text"},
{"name":"Customer ID","type":"numeric"},
{"name":"Items Purchased","type":"numeric"},
{"name":"Date","type":"datetime"}
],
"amount":6
}
Fields Description
3.2. Filtering Dataset Data
This functionality is not available in the API Toolkit and can be performed via direct API calls, such as described in this section.
3.2.1. Limit, Offset, Amount
This API call demonstrates how to apply filtering and sorting by using additional query parameters:
$.ajax({
"url": "/api/dataset_data?dataset=<Dataset ID>&limit=<Number of returned rows>&offset=<Number of rows to skip>&amount=<Y/N>",
"type": "POST",
data:
{
"sort":
[
{"field":"<Field 1 Name>","dir":"<ASC/DESC>"},
{"field":"<Field 2 Name>","dir":"<ASC/DESC>"}
]
},
"headers": {"Accept":"application/json"}
}).done(response=>console.log(response))
Assign dataset
the value of Dataset ID and enter value of the following query parameters to filter out the Dataset data:
-
limit
- the number of returned rows, -
offset
- the number of rows to be skipped before returning any rows, -
amount
- whether to display the total amount of rows in the Dataset.
To sort out the returned data, add an object to the sort
array providing two properties' values:
-
field
: The name of the column by which the Dataset data is filtered. -
dir
: The direction in which the Dataset data is sorted can take one of the two values:-
ASC
: Ascending -
DESC
: Descending
-
Example request:
$.ajax({
"url": "/api/dataset_data?dataset=568&limit=4&offset=1&amount=Y",
"type": "POST",
data:
{
"sort":
[
{"field":"items_purchased","dir":"DESC"},
{"field": "country","dir":"ASC"}
]
},
"headers": {"Accept":"application/json"}
}).done(response=>console.log(response))
3.2.2. Contains
This API call demonstrates how to filter out the Dataset data based on text entry and return only columns that contain entered words or letters.
$.ajax({
"url": '/api/dataset_data?dataset=<Dataset ID>',
"headers": { "Content-type": "application/json", "Accept": "application/json" },
"type": "POST",
"data": JSON.stringify({
"filters": [
{
"column_name": "<Column Name>",
"condition": "contains",
"data": "<Data to filter Columns>"
}
]
})
});
Assign dataset
the value of Dataset ID and enter values of the following filter parameters:
-
column_name
: The filtered column name. -
data
: A text entry by which the column data is filtered.- The text entry can contain one or more symbols or words.
Example request:
$.ajax({
"url": '/api/dataset_data?dataset=568',
"headers": { "Content-type": "application/json", "Accept": "application/json" },
"type": "POST",
"data": JSON.stringify({
"filters": [
{
"column_name": "country",
"condition": "contains",
"data": "Italy"
}
]
})
});
3.2.3. Equals, Is Greater Than, Is Less Than
This API call allows to filter the numeric data of the Dataset:
$.ajax({
"url": '/api/dataset_data?dataset=<Dataset ID>',
"headers": { "Content-type": "application/json", "Accept": "application/json" },
"type": "POST",
"data": JSON.stringify({
filters: [
{
column_name: "<Column Name>",
condition: "<Operator>",
data: "<Numeric Value>"
}
]
})
});
Assign dataset
the value of Dataset ID and enter the values of the following filter parameters:
-
column_name
: The filtered column name. -
condition
: Select one of the three conditions:-
equals
: Returns rows where the column value is equal to the user input -
is greater than
: Returns rows where the column value is greater than the value of user input -
is less than
: Returns rows where the column value is less than the value of user input
-
-
data
: A numeric value
Request example:
$.ajax({
"url": '/api/dataset_data?dataset=568',
"headers": { "Content-type": "application/json", "Accept": "application/json" },
"type": "POST",
"data": JSON.stringify({
filters: [
{
column_name: "items_purchased",
condition: "is less than",
data: "12"
}
]
})
});
3.2.4. Operator AND
This API call allows to return Dataset data which corresponds to multiple filter conditions:
$.ajax({
"url": '/api/dataset_data?dataset=<Dataset ID>',
"headers": { "Content-type": "application/json", "Accept": "application/json" },
"type": "POST",
"data": JSON.stringify({
filters: [
{
group: {
operator: "AND",
rules: [
{
column_name: "<Column Name>",
condition: "<Condition>",
data: "<Data to filter columns>"
},
{
column_name: "<Column Name>",
condition: "<Condition>",
data: "<Data to filter columns>"
}
]
}
}
],
})
});
Assign dataset
the value of Dataset ID. Any number of rules can be applied, each rule can be either a rule with contains condition or equals, is greater than, is less than.
Example request:
$.ajax({
"url": '/api/dataset_data?dataset=568',
"headers": { "Content-type": "application/json", "Accept": "application/json" },
"type": "POST",
"data": JSON.stringify({
filters: [
{
group: {
operator: "AND",
rules: [
{
column_name: "items_purchased",
condition: "is greater than",
data: "10"
},
{
column_name: "country",
condition: "contains",
data: "Italy"
}
]
}
}
],
})
});
3.2.5. Operator OR
This API call allows to return Dataset data which corresponds to at least one of the provided filter conditions:
$.ajax({
"url": '/api/dataset_data?dataset=<Dataset ID>',
"headers": { "Content-type": "application/json", "Accept": "application/json" },
"type": "POST",
"data": JSON.stringify({
filters: [
{
group: {
operator: "OR",
rules: [
{
column_name: "<Column Name>",
condition: "<Condition>",
data: "<Data to filter columns>"
},
{
column_name: "<Column Name>",
condition: "<Condition>",
data: "<Data to filter columns>"
}
]
}
}
],
})
});
Assign dataset
the value of Dataset ID. Any number of rules can be applied, each rule can be either a rule with contains condition or equals, is greater than, is less than.
Example request:
$.ajax({
"url": '/api/dataset_data?dataset=568',
"headers": { "Content-type": "application/json", "Accept": "application/json" },
"type": "POST",
"data": JSON.stringify({
filters: [
{
group: {
operator: "OR",
rules: [
{
column_name: "items_purchased",
condition: "is less than",
data: "15"
},
{
column_name: "country",
condition: "contains",
data: "Canada"
},
]
}
}
],
})
});