HTTP API queries
Overview
HTTP API queries are made using JSON over HTTPS (referred to here as HTTP requests). These API calls can be made with a variety of tools and programming languages. Using the API provides programmatic access to Coralogix's data archive, allowing users to automate queries, integrate with other systems, and perform large-scale or time-sensitive operations that would be less efficient or impractical through the UI.
Requirements
All requests must use HTTPS. Calls made over plain HTTP will fail.
To use this API you need to create a personal or team API key. It’s recommended to use permission presets, as they are automatically updated with all relevant permissions. Alternatively, you can manually add individual permissions.
Any request that lacks proper authentication will be rejected. To authenticate, add an Authorization Bearer <cx_api_key>
header to your API request. It contains a Bearer Token, which identifies a single user, bot user, or workspace-application relationship for authentication.
Use the DataPrime endpoint that matches your Coralogix domain.
Request payload body
When submitting data to a resource via POST
, you must submit your payload in JSON. The only required field in the API body is query
. All other fields are optional and form the metadata object.
Note
Background queries require more fields than just query
. See background queries below.
The following example consists of a JSON object that represents the request:
{
"query": "source logs | limit 100",
"metadata": { // metadata object is optional
"tier": "TIER_FREQUENT_SEARCH", // TIER_ARCHIVE for long term storage
"syntax": "QUERY_SYNTAX_DATAPRIME", // QUERY_SYNTAX_LUCENE for Lucene queries
"startDate": "2023-05-29T11:20:00.00Z", // UTC
"endDate": "2023-05-29T11:30:00.00Z", // UTC
"defaultSource": "logs"
}
}
Note
If the time zone of your timestamp differs, convert it to UTC or offset the timestamp to your time zone by navigating to Account settings > Preferences > Change your time zone settings. For example, to start the query at 11:20 local time:
In San Francisco (Pacific Daylight Time): 2023-05-29T11:20:00.00-07:00
In India (India Standard Time): 2023-05-29T11:20:00.00+05:30
Note
When querying archived logs using the API, you must explicitly specify "tier": "TIER_ARCHIVE"
in the metadata object of your request. Otherwise, the default is "tier": "TIER_FREQUENT_SEARCH"
.
Direct API query
https://api./api/v1/dataprime/query
Warning
ng-api-http.
is deprecated and should not be used
Make the API call
curl --location 'https://api./api/v1/dataprime/query' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <cx_api_key>' \
--data '{
"query": "source logs | limit 10"
}'
Note
When working with curl
or similar command-line tools to make JSON over HTTP API requests, it's important to understand how your shell (typically Bash) processes quotes inside command arguments. This becomes especially relevant when your request payload includes JSON — and even more so when the JSON contains both single and double quotes. Find out more here.
import requests
import json
endpoint = "https://api./api/v1/dataprime/query"
api_key = "<cx_api_key>"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
payload = {"query": "source logs | limit 10"}
response = requests.post(endpoint, headers=headers, json=payload)
if response.status_code == 200:
try:
for part in response.text.strip().split("\n"):
print(json.loads(part))
except json.JSONDecodeError:
print("Response is not valid JSON:")
print(response.text)
else:
print(f"Request failed with status code {response.status_code}")
print(response.text)
const endpoint = 'https://api./api/v1/dataprime/query';
const apiKey = '<cx_api_key>';
const payload = {
query: 'source logs | limit 10',
};
fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify(payload),
})
.then(async (res) => {
const text = await res.text();
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log('Status:', res.status);
console.log('Response:', text);
})
.catch(err => {
console.error('Error:', err);
});
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
url := "https://api./api/v1/dataprime/query"
apiKey := "<cx_api_key>"
payload := []byte(`{
"query": "source logs | limit 10"
}`)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload))
if err != nil {
fmt.Println("Error creating request:", err)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+apiKey)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Request error:", err)
return
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response:", err)
return
}
fmt.Println("Status:", resp.Status)
fmt.Println("Response:")
fmt.Println(string(body))
}
<?php
$url = "https://api./api/v1/dataprime/query";
$apiKey = "<cx_api_key>";
$payload = [
"query" => "source logs | limit 10"
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
"Authorization: Bearer $apiKey"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
$response = curl_exec($ch);
$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Status: $httpStatus\n";
echo "Response: $response\n";
?>
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
public class CoralogixQuery {
public static void main(String[] args) throws Exception {
String endpoint = "https://api./api/v1/dataprime/query";
String apiKey = "<cx_api_key>";
URL url = new URL(endpoint);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Authorization", "Bearer " + apiKey);
con.setDoOutput(true);
String payload = "{\"query\": \"source logs | limit 10\"}";
try (OutputStream os = con.getOutputStream()) {
byte[] input = payload.getBytes("utf-8");
os.write(input, 0, input.length);
}
int status = con.getResponseCode();
InputStream responseStream = (status < 400) ? con.getInputStream() : con.getErrorStream();
BufferedReader in = new BufferedReader(new InputStreamReader(responseStream));
String line;
StringBuilder response = new StringBuilder();
while ((line = in.readLine()) != null) {
response.append(line.trim());
}
in.close();
System.out.println("Status: " + status);
System.out.println("Response: " + response.toString());
}
}
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program {
static async Task Main() {
var client = new HttpClient();
var url = "https://api./api/v1/dataprime/query";
var apiKey = "<cx_api_key>";
var payload = "{\"query\": \"source logs | limit 10\"}";
var content = new StringContent(payload, Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
var response = await client.PostAsync(url, content);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Status: {(int)response.StatusCode}");
Console.WriteLine("Response:");
Console.WriteLine(result);
}
}
API response
The Content-Type
representation header is used to indicate the original media type of the resource (before any content encoding is applied for sending). In responses, a Content-Type
header provides the client with the actual content type of the returned content.
Correct results are returned in batches. Each batch may contain multiple rows of results, which are returned as Newline Delimited JSON or ndjson format.
The response will consist of 2 JSON objects. The first will contain the queryId
and the second will contain the result of the DataPrime query.
{
"queryId": {
"queryId": "12345678-07f8-4313-1234-d954b1b45d31"
}
}
{
"result": {
"results": [
{
"metadata": [
{
"key": "logid",
"value": "c3ca5343-88dc-4807-a8f3-82832274afb7"
}
],
"labels": [
{
"key": "applicationname",
"value": "staging"
}
],
"userData": "{ ... \"log_obj\":{\"level\":\"INFO\",\"message\":\"some log message\" ... }, ...}"
}
]
}
}
Background queries HTTP API overview
The Background Queries JSON over HTTP API enables you to run high-latency, long-running queries asynchronously using DataPrime or Lucene syntax from scripts or the CLI. Designed for recurring, extensive analytical tasks—such as monthly or quarterly reports—this API allows you to offload complex queries to run in the background, freeing you to continue real-time monitoring within the Coralogix platform.
Use it to:
- Seamlessly query archived logs and spans, regardless of time range.
- Leverage higher scan, file, and shuffle limits for deeper data access.
- Take advantage of extended execution times for heavy analytical workloads.
The API supports the following background gRPCs:
- Submit a background query
- Get background query status
- Cancel a background query
- Get background query data
Submit a background query
https://api./api/v1/dataprime/background-query
In addition to the query
field, syntax
, startDate
, and endDate
are required fields for background queries.
Note
The structure of background query requests are different from that of direct query requests, specifically that background query requests don't contain the matadata
nested object.
{
"query": "source logs",
"syntax": "QUERY_SYNTAX_DATAPRIME", // QUERY_SYNTAX_LUCENE for Lucene
"startDate": "2025-01-20T00:00:00Z", // UTC
"endDate": "2025-01-20T01:00:00Z", // UTC
"nowDate": "2025-01-20T02:00:00Z", // (optional field) UTC
"tier": "TIER_ARCHIVE", // (optional field) TIER_FREQUENT_SEARCH for Frequent Search
"limit": 2000 // (optional field) Max number of results. Default is 2000
}
Make the API call
curl --location 'https://api./api/v1/dataprime/background-query' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <cx_api_key>' \
--data '{
"query": "source logs | limit 101",
"syntax": "QUERY_SYNTAX_DATAPRIME",
"startDate": "2025-01-20T00:00:00Z",
"endDate": "2025-01-20T01:00:00Z",
"nowDate": "2025-01-20T02:00:00Z"
}'
import requests
import json
endpoint = "https://api./api/v1/dataprime/background-query"
api_key = "<cx_api_key>"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
payload = {"query": "source logs | limit 10"}
response = requests.post(endpoint, headers=headers, json=payload)
if response.status_code == 200:
try:
for part in response.text.strip().split("\n"):
print(json.loads(part))
except json.JSONDecodeError:
print("Response is not valid JSON:")
print(response.text)
else:
print(f"Request failed with status code {response.status_code}")
print(response.text)
const endpoint = 'https://api./api/v1/dataprime/background-query';
const apiKey = '<cx_api_key>';
const payload = {
query: "source logs | limit 101",
syntax: "QUERY_SYNTAX_DATAPRIME",
startDate: "2025-01-20T00:00:00Z",
endDate: "2025-01-20T01:00:00Z",
nowDate: "2025-01-20T02:00:00Z"
};
fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify(payload),
})
.then(async (res) => {
const text = await res.text();
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log('Status:', res.status);
console.log('Response:', text);
})
.catch(err => {
console.error('Error:', err);
});
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
url := "https://api./api/v1/dataprime/background-query"
apiKey := "<cx_api_key>"
payload := []byte(`{
"query": "source logs | limit 101",
"syntax": "QUERY_SYNTAX_DATAPRIME",
"startDate": "2025-01-20T00:00:00Z",
"endDate": "2025-01-20T01:00:00Z",
"nowDate": "2025-01-20T02:00:00Z"
}`)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload))
if err != nil {
fmt.Println("Error creating request:", err)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+apiKey)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Request error:", err)
return
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response:", err)
return
}
fmt.Println("Status:", resp.Status)
fmt.Println("Response:")
fmt.Println(string(body))
}
<?php
$url = "https://api./api/v1/dataprime/background-query";
$apiKey = "<cx_api_key>";
$payload = [
"query" => "source logs | limit 101",
"syntax" => "QUERY_SYNTAX_DATAPRIME",
"startDate" => "2025-01-20T00:00:00Z",
"endDate" => "2025-01-20T01:00:00Z",
"nowDate" => "2025-01-20T02:00:00Z"
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
"Authorization: Bearer $apiKey"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
$response = curl_exec($ch);
$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Status: $httpStatus\n";
echo "Response: $response\n";
?>
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
public class CoralogixQuery {
public static void main(String[] args) throws Exception {
String endpoint = "https://api./api/v1/dataprime/background-query";
String apiKey = "<cx_api_key>";
URL url = new URL(endpoint);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Authorization", "Bearer " + apiKey);
con.setDoOutput(true);
String payload = """
{
"query": "limit 101",
"syntax": "QUERY_SYNTAX_DATAPRIME",
"startDate": "2025-01-20T00:00:00Z",
"endDate": "2025-01-20T01:00:00Z",
"nowDate": "2025-01-20T02:00:00Z"
}
""";
try (OutputStream os = con.getOutputStream()) {
byte[] input = payload.getBytes("utf-8");
os.write(input, 0, input.length);
}
int status = con.getResponseCode();
InputStream responseStream = (status < 400) ? con.getInputStream() : con.getErrorStream();
BufferedReader in = new BufferedReader(new InputStreamReader(responseStream));
String line;
StringBuilder response = new StringBuilder();
while ((line = in.readLine()) != null) {
response.append(line.trim());
}
in.close();
System.out.println("Status: " + status);
System.out.println("Response: " + response.toString());
}
}
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program {
static async Task Main() {
var client = new HttpClient();
var url = "https://api./api/v1/dataprime/background-query";
var apiKey = "<cx_api_key>";
var payload = "{"
+ "\"query\": \"limit 101\","
+ "\"syntax\": \"QUERY_SYNTAX_DATAPRIME\","
+ "\"startDate\": \"2025-01-20T00:00:00Z\","
+ "\"endDate\": \"2025-01-20T01:00:00Z\","
+ "\"nowDate\": \"2025-01-20T02:00:00Z\""
+ "}";
var content = new StringContent(payload, Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
var response = await client.PostAsync(url, content);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Status: {(int)response.StatusCode}");
Console.WriteLine("Response:");
Console.WriteLine(result);
}
}
Response
The response object contains a queryId
. This ID is used to do follow up operations on the background query.
Get background query status
https://api./api/v1/dataprime/background-query/status
Make the API call
import requests
import json
endpoint = "https://api./api/v1/dataprime/background-query/status"
api_key = "<cx_api_key>"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
payload = {"queryId": "c80fa3e7-fa5b-441a-b0d4-acdbdbe36e64"}
response = requests.post(endpoint, headers=headers, json=payload)
if response.status_code == 200:
try:
for part in response.text.strip().split("\n"):
print(json.loads(part))
except json.JSONDecodeError:
print("Response is not valid JSON:")
print(response.text)
else:
print(f"Request failed with status code {response.status_code}")
print(response.text)
const endpoint = 'https://api./api/v1/dataprime/background-query/status';
const apiKey = '<cx_api_key>';
const payload = {queryId: "c80fa3e7-fa5b-441a-b0d4-acdbdbe36e64"};
fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify(payload),
})
.then(async (res) => {
const text = await res.text();
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log('Status:', res.status);
console.log('Response:', text);
})
.catch(err => {
console.error('Error:', err);
});
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
url := "https://api./api/v1/dataprime/background-query/status"
apiKey := "<cx_api_key>"
payload := []byte(`{"queryId": "c80fa3e7-fa5b-441a-b0d4-acdbdbe36e64"}`)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload))
if err != nil {
fmt.Println("Error creating request:", err)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+apiKey)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Request error:", err)
return
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response:", err)
return
}
fmt.Println("Status:", resp.Status)
fmt.Println("Response:")
fmt.Println(string(body))
}
<?php
$url = "https://api./api/v1/dataprime/background-query/status";
$apiKey = "<cx_api_key>";
$payload = ["queryId" => "c80fa3e7-fa5b-441a-b0d4-acdbdbe36e64"];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
"Authorization: Bearer $apiKey"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
$response = curl_exec($ch);
$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Status: $httpStatus\n";
echo "Response: $response\n";
?>
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
public class CoralogixQuery {
public static void main(String[] args) throws Exception {
String endpoint = "https://api./api/v1/dataprime/background-query/status";
String apiKey = "<cx_api_key>";
URL url = new URL(endpoint);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Authorization", "Bearer " + apiKey);
con.setDoOutput(true);
String payload = "{\"queryId\": \"c80fa3e7-fa5b-441a-b0d4-acdbdbe36e64\"}";
try (OutputStream os = con.getOutputStream()) {
byte[] input = payload.getBytes("utf-8");
os.write(input, 0, input.length);
}
int status = con.getResponseCode();
InputStream responseStream = (status < 400) ? con.getInputStream() : con.getErrorStream();
BufferedReader in = new BufferedReader(new InputStreamReader(responseStream));
String line;
StringBuilder response = new StringBuilder();
while ((line = in.readLine()) != null) {
response.append(line.trim());
}
in.close();
System.out.println("Status: " + status);
System.out.println("Response: " + response.toString());
}
}
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program {
static async Task Main() {
var client = new HttpClient();
var url = "https://api./api/v1/dataprime/background-query/status";
var apiKey = "<cx_api_key>";
var payload = "{\"queryId\": \"c80fa3e7-fa5b-441a-b0d4-acdbdbe36e64\"}"
var content = new StringContent(payload, Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
var response = await client.PostAsync(url, content);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Status: {(int)response.StatusCode}");
Console.WriteLine("Response:");
Console.WriteLine(result);
}
}
Response
{
"terminated": {
"runningSince": "2025-01-23T15:16:01Z",
"terminatedAt": "2025-01-23T15:16:01Z",
"success": {}
},
"submittedAt": "2025-01-23T15:15:58Z",
"metadata": [
{
"statistics": {
"bytesScanned": "506070"
}
}
],
"warnings": []
}
Cancel a background query
https://api./api/v1/dataprime/background-query/cancel
Make the API call
import requests
import json
endpoint = "https://api./api/v1/dataprime/background-query/cancel"
api_key = "<cx_api_key>"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
payload = {"queryId": "c80fa3e7-fa5b-441a-b0d4-acdbdbe36e64"}
response = requests.post(endpoint, headers=headers, json=payload)
if response.status_code == 200:
try:
for part in response.text.strip().split("\n"):
print(json.loads(part))
except json.JSONDecodeError:
print("Response is not valid JSON:")
print(response.text)
else:
print(f"Request failed with status code {response.status_code}")
print(response.text)
const endpoint = 'https://api./api/v1/dataprime/background-query/cancel';
const apiKey = '<cx_api_key>';
const payload = {queryId: "c80fa3e7-fa5b-441a-b0d4-acdbdbe36e64"};
fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify(payload),
})
.then(async (res) => {
const text = await res.text();
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log('Status:', res.status);
console.log('Response:', text);
})
.catch(err => {
console.error('Error:', err);
});
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
url := "https://api./api/v1/dataprime/background-query/cancel"
apiKey := "<cx_api_key>"
payload := []byte(`{"queryId": "c80fa3e7-fa5b-441a-b0d4-acdbdbe36e64"}`)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload))
if err != nil {
fmt.Println("Error creating request:", err)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+apiKey)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Request error:", err)
return
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response:", err)
return
}
fmt.Println("Status:", resp.Status)
fmt.Println("Response:")
fmt.Println(string(body))
}
<?php
$url = "https://api./api/v1/dataprime/background-query/cancel";
$apiKey = "<cx_api_key>";
$payload = ["queryId" => "c80fa3e7-fa5b-441a-b0d4-acdbdbe36e64"];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
"Authorization: Bearer $apiKey"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
$response = curl_exec($ch);
$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Status: $httpStatus\n";
echo "Response: $response\n";
?>
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
public class CoralogixQuery {
public static void main(String[] args) throws Exception {
String endpoint = "https://api./api/v1/dataprime/background-query/cancel";
String apiKey = "<cx_api_key>";
URL url = new URL(endpoint);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Authorization", "Bearer " + apiKey);
con.setDoOutput(true);
String payload = "{\"queryId\": \"c80fa3e7-fa5b-441a-b0d4-acdbdbe36e64\"}";
try (OutputStream os = con.getOutputStream()) {
byte[] input = payload.getBytes("utf-8");
os.write(input, 0, input.length);
}
int status = con.getResponseCode();
InputStream responseStream = (status < 400) ? con.getInputStream() : con.getErrorStream();
BufferedReader in = new BufferedReader(new InputStreamReader(responseStream));
String line;
StringBuilder response = new StringBuilder();
while ((line = in.readLine()) != null) {
response.append(line.trim());
}
in.close();
System.out.println("Status: " + status);
System.out.println("Response: " + response.toString());
}
}
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program {
static async Task Main() {
var client = new HttpClient();
var url = "https://api./api/v1/dataprime/background-query/cancel";
var apiKey = "<cx_api_key>";
var payload = "{\"queryId\": \"c80fa3e7-fa5b-441a-b0d4-acdbdbe36e64\"}"
var content = new StringContent(payload, Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
var response = await client.PostAsync(url, content);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Status: {(int)response.StatusCode}");
Console.WriteLine("Response:");
Console.WriteLine(result);
}
}
Response
Get background query data
https://api./api/v1/dataprime/background-query/data
Make the API call
import requests
import json
endpoint = "https://api./api/v1/dataprime/background-query/data"
api_key = "<cx_api_key>"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
payload = {"queryId": "c80fa3e7-fa5b-441a-b0d4-acdbdbe36e64"}
response = requests.post(endpoint, headers=headers, json=payload)
if response.status_code == 200:
try:
for part in response.text.strip().split("\n"):
print(json.loads(part))
except json.JSONDecodeError:
print("Response is not valid JSON:")
print(response.text)
else:
print(f"Request failed with status code {response.status_code}")
print(response.text)
const endpoint = 'https://api./api/v1/dataprime/background-query/data';
const apiKey = '<cx_api_key>';
const payload = {queryId: "c80fa3e7-fa5b-441a-b0d4-acdbdbe36e64"};
fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify(payload),
})
.then(async (res) => {
const text = await res.text();
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log('Status:', res.status);
console.log('Response:', text);
})
.catch(err => {
console.error('Error:', err);
});
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
url := "https://api./api/v1/dataprime/background-query/data"
apiKey := "<cx_api_key>"
payload := []byte(`{"queryId": "c80fa3e7-fa5b-441a-b0d4-acdbdbe36e64"}`)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload))
if err != nil {
fmt.Println("Error creating request:", err)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+apiKey)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Request error:", err)
return
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response:", err)
return
}
fmt.Println("Status:", resp.Status)
fmt.Println("Response:")
fmt.Println(string(body))
}
<?php
$url = "https://api./api/v1/dataprime/background-query/data";
$apiKey = "<cx_api_key>";
$payload = ["queryId" => "c80fa3e7-fa5b-441a-b0d4-acdbdbe36e64"];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
"Authorization: Bearer $apiKey"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
$response = curl_exec($ch);
$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Status: $httpStatus\n";
echo "Response: $response\n";
?>
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
public class CoralogixQuery {
public static void main(String[] args) throws Exception {
String endpoint = "https://api./api/v1/dataprime/background-query/data";
String apiKey = "<cx_api_key>";
URL url = new URL(endpoint);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Authorization", "Bearer " + apiKey);
con.setDoOutput(true);
String payload = "{\"queryId\": \"c80fa3e7-fa5b-441a-b0d4-acdbdbe36e64\"}";
try (OutputStream os = con.getOutputStream()) {
byte[] input = payload.getBytes("utf-8");
os.write(input, 0, input.length);
}
int status = con.getResponseCode();
InputStream responseStream = (status < 400) ? con.getInputStream() : con.getErrorStream();
BufferedReader in = new BufferedReader(new InputStreamReader(responseStream));
String line;
StringBuilder response = new StringBuilder();
while ((line = in.readLine()) != null) {
response.append(line.trim());
}
in.close();
System.out.println("Status: " + status);
System.out.println("Response: " + response.toString());
}
}
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program {
static async Task Main() {
var client = new HttpClient();
var url = "https://api./api/v1/dataprime/background-query/data";
var apiKey = "<cx_api_key>";
var payload = "{\"queryId\": \"c80fa3e7-fa5b-441a-b0d4-acdbdbe36e64\"}"
var content = new StringContent(payload, Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
var response = await client.PostAsync(url, content);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Status: {(int)response.StatusCode}");
Console.WriteLine("Response:");
Console.WriteLine(result);
}
}
Response
{
"response": {
"results": {
"results": [
{
"metadata": [...],
"labels": [...],
"userData": "..."
},
...
]
}
}
},
{
...
}
...
Response handling
The Content-Type
representation header indicates the original media type of the resource before any content encoding is applied for transmission.
In responses, the Content-Type
header informs the client of the actual content type of the returned data.
Data endpoint results are returned in batches, with each batch containing multiple rows formatted as Newline Delimited JSON (NDJSON). Other types of responses are returned in standard JSON format.
Failed requests
The general format guidelines are displayed when the accompanying status code is returned.
Status code | Description |
---|---|
200 | No Error |
400 | Bad Request |
403 | Forbidden |
A 400
error typically means the user made a malformed request.
A 403
error typically means that there was problem with the API key. See your API keys page or administrator for more information.
Warnings
The Warning
response contains information about possible problems with the status of the message. More than one Warning
header may appear in a response.
Warning
responses can be applied to any message, before or after query results.
Warning type | Description |
---|---|
CompileWarning | Warning of potential compilation error in your query. In the event of a compilation failure, you will receive an error response. |
TimeRangeWarning | When the time frame for your query has been built incorrectly or exceeds internal limits |
NumberOfResultsLimitWarning | When the number of query results exceeds internal limits |
BytesScannedLimitWarning | When the number of bytes returned in query results exceeds internal limits |
DeprecationWarning | When a value in your query is changed or deprecated incorrectly |
Limitations
When a limit is breached, a warning message is displayed.
See the limitations page for a comprehensive list of limitations.