curl --request POST \
--url https://api.statisfy.com/v1/reports/query \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"sql": "<string>",
"limit": 100
}
'import requests
url = "https://api.statisfy.com/v1/reports/query"
payload = {
"sql": "<string>",
"limit": 100
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({sql: '<string>', limit: 100})
};
fetch('https://api.statisfy.com/v1/reports/query', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.statisfy.com/v1/reports/query",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'sql' => '<string>',
'limit' => 100
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.statisfy.com/v1/reports/query"
payload := strings.NewReader("{\n \"sql\": \"<string>\",\n \"limit\": 100\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.statisfy.com/v1/reports/query")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"sql\": \"<string>\",\n \"limit\": 100\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.statisfy.com/v1/reports/query")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"sql\": \"<string>\",\n \"limit\": 100\n}"
response = http.request(request)
puts response.read_body{
"columns": [
{
"name": "<string>",
"type": "number"
}
],
"rows": [
[
"<unknown>"
]
],
"sql": "<string>",
"truncated": true
}Run report SQL
Runs your SQL over the report views and returns its rows (up to limit, at most 1000). Send one SELECT (WITH, UNION, INTERSECT and EXCEPT are fine) over the report views GET /v1/reports/sources lists, named without a schema. Only listed functions run: aggregates; window functions; common date, number, text, array and conditional functions; and JSON field access (->, ->>, #>, #>>). JSON-building functions (such as json_agg) and operators such as ~*, @> and && aren’t available. Any other function, a table that isn’t a report view, another schema, or a setting is refused with a 422 listing each problem. It runs read-only with the time zone set to UTC, stops after about 15 seconds (a 504), and refuses a result over 32 MB or a row over 4 MB (a 422). Your workspace runs a few report queries at once on each server; one past that waits a few seconds, then is a 429 with Retry-After. lpad and rpad take a length of at most 10000, written as a number. SQL the database refuses (a missing column, a bad cast) is a 422 with Postgres’s message. These are the API’s own rules: the reports page runs a widget’s SQL with the report’s filters and the viewer’s scope added, allows it 30 seconds, and checks SQL its own way, so results and refusals can differ. Safe to retry: it only reads.
curl --request POST \
--url https://api.statisfy.com/v1/reports/query \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"sql": "<string>",
"limit": 100
}
'import requests
url = "https://api.statisfy.com/v1/reports/query"
payload = {
"sql": "<string>",
"limit": 100
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({sql: '<string>', limit: 100})
};
fetch('https://api.statisfy.com/v1/reports/query', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.statisfy.com/v1/reports/query",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'sql' => '<string>',
'limit' => 100
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.statisfy.com/v1/reports/query"
payload := strings.NewReader("{\n \"sql\": \"<string>\",\n \"limit\": 100\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.statisfy.com/v1/reports/query")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"sql\": \"<string>\",\n \"limit\": 100\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.statisfy.com/v1/reports/query")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"sql\": \"<string>\",\n \"limit\": 100\n}"
response = http.request(request)
puts response.read_body{
"columns": [
{
"name": "<string>",
"type": "number"
}
],
"rows": [
[
"<unknown>"
]
],
"sql": "<string>",
"truncated": true
}Authorizations
An API key, sent as Authorization: Bearer stfy_live_…. See Authentication for how to get one and which scopes it needs.
Body
Send one SELECT (WITH, UNION, INTERSECT and EXCEPT are fine) over the report views GET /v1/reports/sources lists, named without a schema. Only listed functions run: aggregates; window functions; common date, number, text, array and conditional functions; and JSON field access (->, ->>, #>, #>>). JSON-building functions (such as json_agg) and operators such as ~*, @> and && aren't available. Any other function, a table that isn't a report view, another schema, or a setting is refused with a 422 listing each problem.
1 - 20000Response
Successful Response
Was this page helpful?