Ask or search…
Comment on page

Accessing Reports results via API

This page describes how to access report results via API

Finding Query ID Via UI

Once the query is created in the UI editor interface, tested, and executed successfully. The query ID can be looked at via the web URL address.
Query ID
The query can then be accessed via API's using the query ID.
Get Query By Id
The query result can be extracted via API via the query ID after the API query.
Get Results by result_id

Python Example I

import requests
import json
uri_query = 'https://logs.logiq.ai/api/queries/<query_id>'
uri_result = 'https://logs.logiq.ai/api/query_results/'
def post_query():
# Add api key to header
headers = {'Authorization': 'Key see_below_to_get_api_key'}
# GET Query API to get latest_query_data_id
r = requests.get(uri_query, headers=headers, verify=False)
# From the queries API extract the latest report id
latest_report_id = r.json()['latest_query_data_id']
# Construct the results url
uri_result_end = uri_result + str(latest_report_id)
# GET Results API
qr = requests.get(uri_result_end, headers=headers, verify=False)
# Prints results
print(json.dumps(qr.json()['query_result']['data']['rows'], indent = 3))

Obtain API Key

API key can be obtained via the UI.
Retrieve API Key

Python Example II

Based on a similar method, this query API directly queries the internal Prometheus data using the Prometheus database access API logiq_proxy.
import requests
import simplejson as json
import time
api_key = "<API_KEY>"
uri_result = input("Enter Query Result URL: ")
json_data = json.loads(input("Enter Query JSON Data: "))
file_name = "output_" + str(time.time()) + ".json"
def post_results_query():
headers = {'Authorization': api_key}
r = requests.post(uri_result, headers=headers, json=json_data, verify=False)
with open(file_name, 'w') as output:
json.dump(r.json(), output, indent=3)
print(json.dumps(r.json(), indent=3))
print("JSON data saved in: " + file_name)
# Example for the logiq_proxy
# URL:
# https://lqnnn.logiq.ai/api/logiq_proxy
# Query Data:
# {"query": "(round(sum by (exported_namespace,app,severity)(increase(logiq_namespace_app_message_count{exported_namespace=~\"logiq:awesj\"}[3600s]))))&start=1700209381&end=1700212981","type": "query"}