Custom queries
Run your own read-only SQL SELECT against a project. See the Custom queries guide for the syntax and limits.
Background and examples: Custom queries
Run a query
/v1/data/query
Runs a custom SELECT query.
Parameters
-
projectuuid query required The GUID of the project.
Request body application/json
The query and the values of its parameters.
-
querystring required One SELECT statement, using table and field names as in the database designer. Use @name for parameters.
-
parametersobject The values of the @parameters in the query, by name.
Responses
- 200 Returns the result of the query.
- 400 If the query is not allowed or not valid (every problem is listed with its line and column), took too long or failed.
- 401 If the user is not signed in.
- 403 If the tier doesn't include custom queries or a table can't be read by the caller.
- 429 If too many custom queries are already running for the project.
Request
curl -X POST 'https://api.stellards.io/v1/data/query?project=PROJECT_ID' \
-H 'Authorization: Bearer ACCESS_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"query": "select c.name, count(o.id) as orders from customers c left join orders o on o.customer = c.id where c.city = @city group by c.name",
"parameters": {
"city": "Ghent"
}
}'
const response = await fetch("https://api.stellards.io/v1/data/query?project=PROJECT_ID", {
method: "POST",
headers: {
Authorization: "Bearer ACCESS_TOKEN",
"Content-Type": "application/json",
},
body: JSON.stringify({
"query": "select c.name, count(o.id) as orders from customers c left join orders o on o.customer = c.id where c.city = @city group by c.name",
"parameters": {
"city": "Ghent"
}
}),
});
const result = await response.json();
console.log(result);
import requests
response = requests.post(
"https://api.stellards.io/v1/data/query?project=PROJECT_ID",
headers={"Authorization": "Bearer ACCESS_TOKEN"},
json={
"query": "select c.name, count(o.id) as orders from customers c left join orders o on o.customer = c.id where c.city = @city group by c.name",
"parameters": {
"city": "Ghent",
},
},
)
print(response.json())
using System.Net.Http.Headers;
using System.Text;
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "ACCESS_TOKEN");
var body = new StringContent("""
{
"query": "select c.name, count(o.id) as orders from customers c left join orders o on o.customer = c.id where c.city = @city group by c.name",
"parameters": {
"city": "Ghent"
}
}
""", Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.stellards.io/v1/data/query?project=PROJECT_ID", body);
Console.WriteLine(await response.Content.ReadAsStringAsync());
uses
System.Classes, System.SysUtils, System.Net.HttpClient, System.Net.URLClient;
var
Client: THTTPClient;
Response: IHTTPResponse;
Body: TStringStream;
begin
Client := THTTPClient.Create;
Body := TStringStream.Create(
'{' +
' "query": "select c.name, count(o.id) as orders from customers c left join orders o on o.customer = c.id where c.city = @city group by c.name",' +
' "parameters": {' +
' "city": "Ghent"' +
' }' +
'}',
TEncoding.UTF8);
try
Client.CustomHeaders['Authorization'] := 'Bearer ACCESS_TOKEN';
Client.ContentType := 'application/json';
Response := Client.Post('https://api.stellards.io/v1/data/query?project=PROJECT_ID', Body);
Writeln(Response.ContentAsString);
finally
Body.Free;
Client.Free;
end;
end;
Response 200
{
"messages": [],
"isSuccess": true,
"data": {
"columns": [
{
"name": "Customers",
"type": "NVarChar(255)"
}
],
"rows": [
{}
],
"count": 1,
"truncated": false,
"durationMs": 38
}
}
Check a query
/v1/data/query/validate
Checks a custom SELECT query without running it, the way the console's editor does while you type. Field names are checked as well. It is not counted against the request limit or kept in the query log.
Parameters
-
projectuuid query required The GUID of the project.
Request body application/json
The query and the names of the parameters it may use.
-
querystring required -
parametersstring[]
Responses
- 200 Returns the problems, if any.
- 401 If the caller is not signed in.
- 403 If the tier doesn't include custom queries.
Request
curl -X POST 'https://api.stellards.io/v1/data/query/validate?project=PROJECT_ID' \
-H 'Authorization: Bearer ACCESS_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"query": "select c.name from customers c where c.city = @city",
"parameters": [
"city"
]
}'
const response = await fetch("https://api.stellards.io/v1/data/query/validate?project=PROJECT_ID", {
method: "POST",
headers: {
Authorization: "Bearer ACCESS_TOKEN",
"Content-Type": "application/json",
},
body: JSON.stringify({
"query": "select c.name from customers c where c.city = @city",
"parameters": [
"city"
]
}),
});
const result = await response.json();
console.log(result);
import requests
response = requests.post(
"https://api.stellards.io/v1/data/query/validate?project=PROJECT_ID",
headers={"Authorization": "Bearer ACCESS_TOKEN"},
json={
"query": "select c.name from customers c where c.city = @city",
"parameters": ["city"],
},
)
print(response.json())
using System.Net.Http.Headers;
using System.Text;
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "ACCESS_TOKEN");
var body = new StringContent("""
{
"query": "select c.name from customers c where c.city = @city",
"parameters": [
"city"
]
}
""", Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.stellards.io/v1/data/query/validate?project=PROJECT_ID", body);
Console.WriteLine(await response.Content.ReadAsStringAsync());
uses
System.Classes, System.SysUtils, System.Net.HttpClient, System.Net.URLClient;
var
Client: THTTPClient;
Response: IHTTPResponse;
Body: TStringStream;
begin
Client := THTTPClient.Create;
Body := TStringStream.Create(
'{' +
' "query": "select c.name from customers c where c.city = @city",' +
' "parameters": [' +
' "city"' +
' ]' +
'}',
TEncoding.UTF8);
try
Client.CustomHeaders['Authorization'] := 'Bearer ACCESS_TOKEN';
Client.ContentType := 'application/json';
Response := Client.Post('https://api.stellards.io/v1/data/query/validate?project=PROJECT_ID', Body);
Writeln(Response.ContentAsString);
finally
Body.Free;
Client.Free;
end;
end;
Response 200
{
"messages": [],
"isSuccess": true,
"data": {
"valid": false,
"problems": []
}
}
List the names a query can use
/v1/data/query/schema
The names a custom query can use: the tables the caller can read with their fields, and the allowed functions.
Parameters
-
projectuuid query required The GUID of the project.
Responses
- 200 Returns the tables and functions.
- 401 If the caller is not signed in.
- 403 If the tier doesn't include custom queries.
Request
curl -X GET 'https://api.stellards.io/v1/data/query/schema?project=PROJECT_ID' \
-H 'Authorization: Bearer ACCESS_TOKEN'
const response = await fetch("https://api.stellards.io/v1/data/query/schema?project=PROJECT_ID", {
headers: {
Authorization: "Bearer ACCESS_TOKEN",
},
});
const result = await response.json();
console.log(result);
import requests
response = requests.get(
"https://api.stellards.io/v1/data/query/schema?project=PROJECT_ID",
headers={"Authorization": "Bearer ACCESS_TOKEN"},
)
print(response.json())
using System.Net.Http.Headers;
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "ACCESS_TOKEN");
var response = await client.GetAsync("https://api.stellards.io/v1/data/query/schema?project=PROJECT_ID");
Console.WriteLine(await response.Content.ReadAsStringAsync());
uses
System.Classes, System.SysUtils, System.Net.HttpClient, System.Net.URLClient;
var
Client: THTTPClient;
Response: IHTTPResponse;
begin
Client := THTTPClient.Create;
try
Client.CustomHeaders['Authorization'] := 'Bearer ACCESS_TOKEN';
Response := Client.Get('https://api.stellards.io/v1/data/query/schema?project=PROJECT_ID');
Writeln(Response.ContentAsString);
finally
Client.Free;
end;
end;
Response 200
{
"messages": [],
"isSuccess": true,
"data": {
"tables": [
4
],
"functions": [
"string"
]
}
}
Run a query Path-style route
/project/{project}/query
Runs a custom SELECT query.
Parameters
-
projectuuid path required The GUID of the project. Provided as a route parameter.
Request body application/json
The query and the values of its parameters.
-
querystring required One SELECT statement, using table and field names as in the database designer. Use @name for parameters.
-
parametersobject The values of the @parameters in the query, by name.
Responses
- 200 Returns the result of the query.
- 400 If the query is not allowed or not valid (every problem is listed with its line and column), took too long or failed.
- 401 If the caller is not signed in and has no valid access token.
- 403 If the tier doesn't include custom queries or a table can't be read by the caller.
- 429 If too many custom queries are already running for the project.
Request
curl -X POST 'https://api.stellards.io/project/PROJECT_ID/query' \
-H 'Authorization: Bearer ACCESS_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"query": "select c.name, count(o.id) as orders from customers c left join orders o on o.customer = c.id where c.city = @city group by c.name",
"parameters": {
"city": "Ghent"
}
}'
const response = await fetch("https://api.stellards.io/project/PROJECT_ID/query", {
method: "POST",
headers: {
Authorization: "Bearer ACCESS_TOKEN",
"Content-Type": "application/json",
},
body: JSON.stringify({
"query": "select c.name, count(o.id) as orders from customers c left join orders o on o.customer = c.id where c.city = @city group by c.name",
"parameters": {
"city": "Ghent"
}
}),
});
const result = await response.json();
console.log(result);
import requests
response = requests.post(
"https://api.stellards.io/project/PROJECT_ID/query",
headers={"Authorization": "Bearer ACCESS_TOKEN"},
json={
"query": "select c.name, count(o.id) as orders from customers c left join orders o on o.customer = c.id where c.city = @city group by c.name",
"parameters": {
"city": "Ghent",
},
},
)
print(response.json())
using System.Net.Http.Headers;
using System.Text;
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "ACCESS_TOKEN");
var body = new StringContent("""
{
"query": "select c.name, count(o.id) as orders from customers c left join orders o on o.customer = c.id where c.city = @city group by c.name",
"parameters": {
"city": "Ghent"
}
}
""", Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.stellards.io/project/PROJECT_ID/query", body);
Console.WriteLine(await response.Content.ReadAsStringAsync());
uses
System.Classes, System.SysUtils, System.Net.HttpClient, System.Net.URLClient;
var
Client: THTTPClient;
Response: IHTTPResponse;
Body: TStringStream;
begin
Client := THTTPClient.Create;
Body := TStringStream.Create(
'{' +
' "query": "select c.name, count(o.id) as orders from customers c left join orders o on o.customer = c.id where c.city = @city group by c.name",' +
' "parameters": {' +
' "city": "Ghent"' +
' }' +
'}',
TEncoding.UTF8);
try
Client.CustomHeaders['Authorization'] := 'Bearer ACCESS_TOKEN';
Client.ContentType := 'application/json';
Response := Client.Post('https://api.stellards.io/project/PROJECT_ID/query', Body);
Writeln(Response.ContentAsString);
finally
Body.Free;
Client.Free;
end;
end;
Response 200
{
"messages": [],
"isSuccess": true,
"data": {
"columns": [
{
"name": "Customers",
"type": "NVarChar(255)"
}
],
"rows": [
{}
],
"count": 1,
"truncated": false,
"durationMs": 38
}
}
List the names a query can use Path-style route
/project/{project}/query/schema
The names a custom query can use: the tables the caller can read with their fields, and the allowed functions.
Parameters
-
projectuuid path required The GUID of the project. Provided as a route parameter.
Responses
- 200 Returns the tables and functions.
- 401 If the caller is not signed in and has no valid access token.
- 403 If the tier doesn't include custom queries.
Request
curl -X GET 'https://api.stellards.io/project/PROJECT_ID/query/schema' \
-H 'Authorization: Bearer ACCESS_TOKEN'
const response = await fetch("https://api.stellards.io/project/PROJECT_ID/query/schema", {
headers: {
Authorization: "Bearer ACCESS_TOKEN",
},
});
const result = await response.json();
console.log(result);
import requests
response = requests.get(
"https://api.stellards.io/project/PROJECT_ID/query/schema",
headers={"Authorization": "Bearer ACCESS_TOKEN"},
)
print(response.json())
using System.Net.Http.Headers;
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "ACCESS_TOKEN");
var response = await client.GetAsync("https://api.stellards.io/project/PROJECT_ID/query/schema");
Console.WriteLine(await response.Content.ReadAsStringAsync());
uses
System.Classes, System.SysUtils, System.Net.HttpClient, System.Net.URLClient;
var
Client: THTTPClient;
Response: IHTTPResponse;
begin
Client := THTTPClient.Create;
try
Client.CustomHeaders['Authorization'] := 'Bearer ACCESS_TOKEN';
Response := Client.Get('https://api.stellards.io/project/PROJECT_ID/query/schema');
Writeln(Response.ContentAsString);
finally
Client.Free;
end;
end;
Response 200
{
"messages": [],
"isSuccess": true,
"data": {
"tables": [
4
],
"functions": [
"string"
]
}
}
Check a query Path-style route
/project/{project}/query/validate
Checks a custom SELECT query without running it, the way the console's editor does while you type. Field names are checked as well. It is not counted against the request limit or kept in the query log.
Parameters
-
projectuuid path required The GUID of the project. Provided as a route parameter.
Request body application/json
The query and the names of the parameters it may use.
-
querystring required -
parametersstring[]
Responses
- 200 Returns the problems, if any.
- 401 If the caller is not signed in and has no valid access token.
- 403 If the tier doesn't include custom queries.
Request
curl -X POST 'https://api.stellards.io/project/PROJECT_ID/query/validate' \
-H 'Authorization: Bearer ACCESS_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"query": "select c.name from customers c where c.city = @city",
"parameters": [
"city"
]
}'
const response = await fetch("https://api.stellards.io/project/PROJECT_ID/query/validate", {
method: "POST",
headers: {
Authorization: "Bearer ACCESS_TOKEN",
"Content-Type": "application/json",
},
body: JSON.stringify({
"query": "select c.name from customers c where c.city = @city",
"parameters": [
"city"
]
}),
});
const result = await response.json();
console.log(result);
import requests
response = requests.post(
"https://api.stellards.io/project/PROJECT_ID/query/validate",
headers={"Authorization": "Bearer ACCESS_TOKEN"},
json={
"query": "select c.name from customers c where c.city = @city",
"parameters": ["city"],
},
)
print(response.json())
using System.Net.Http.Headers;
using System.Text;
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "ACCESS_TOKEN");
var body = new StringContent("""
{
"query": "select c.name from customers c where c.city = @city",
"parameters": [
"city"
]
}
""", Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.stellards.io/project/PROJECT_ID/query/validate", body);
Console.WriteLine(await response.Content.ReadAsStringAsync());
uses
System.Classes, System.SysUtils, System.Net.HttpClient, System.Net.URLClient;
var
Client: THTTPClient;
Response: IHTTPResponse;
Body: TStringStream;
begin
Client := THTTPClient.Create;
Body := TStringStream.Create(
'{' +
' "query": "select c.name from customers c where c.city = @city",' +
' "parameters": [' +
' "city"' +
' ]' +
'}',
TEncoding.UTF8);
try
Client.CustomHeaders['Authorization'] := 'Bearer ACCESS_TOKEN';
Client.ContentType := 'application/json';
Response := Client.Post('https://api.stellards.io/project/PROJECT_ID/query/validate', Body);
Writeln(Response.ContentAsString);
finally
Body.Free;
Client.Free;
end;
end;
Response 200
{
"messages": [],
"isSuccess": true,
"data": {
"valid": false,
"problems": []
}
}