In this article, we will look at how to get time series data from the platform, what API endpoints to use, and what data to use to run API queries.


First of all, you need to log in to the Cital Insights platform

Authorization with REST API endpoints



Authorization with ThingsBoard REST client

from tb_rest_client.rest_client_ce import *

# Cital Insights REST API URL
url = "https://iot.cital.io:443"
# User credentials
username = "username@mail.com"
password = "user_password"

# Creating the REST client object with context manager to get auto token refresh
with RestClientCE(base_url=url) as rest_client:
    # Auth with credentials
    rest_client.login(username=username, password=password)
    # Get user info
    current_user = rest_client.get_user()

Entity view data

After authorization, the entity view data can be fetched with the entity view controller. You should use the entity type and the entity ID for further actions.

Get entity view data with REST API endpoints


Get entity view data with ThingsBoard REST client

    # Get entity view data
    customer_id = current_user.customer_id.id
    entity_view_data = rest_client.get_customer_entity_views(
        customer_id=current_user.customer_id.id, page=0, page_size=10)

Time-series data

We need to prepare some data for the next request. Dates should be converted to timestamp format. You can read about it here:  How to convert a date to a UTC timestamp? Then EntityViewID object should be created.

Get telemetry data with REST API endpoints


Get telemetry data with the ThingsBoard REST client

import datetime

    # Get time-series data
    start_ts = datetime_to_timestamp(datetime.datetime(2023, 2, 14, 0, 0, 0))
    end_ts = datetime_to_timestamp(datetime.datetime(2023, 2, 15, 0, 0, 0))
    entity_view_id = EntityViewId(
    telemetry_data = rest_client.get_timeseries(
        entity_id=entity_view_id, keys="tempOffBoard,waterPotOffBoard", start_ts=start_ts,

Import to CSV format

If you want to import downloaded data to CSV format you can use the code snippet below. We are using pandas library for the implementation of this code.

import pandas as pd

    # First create individual Dataframes for each time series
    tempOnBoard_df = pd.DataFrame(
    waterPotOffBoard_df =pd.DataFrame(
    # Merge all Single Dataframes
    final_df = pd.concat([tempOnBoard_df, waterPotOffBoard_df], join='outer', axis=1)
    final_df.columns = ["tempOnBoard", "waterPotOffBoard"]
    # Easy CSV export possible

Have a question?