Execute a Query | Data Analytics
Running your queries is pretty straightforward, you only need the query id and any optional variables required.
1. Check Your Queries for the Query ID
List available Queries using the List Queries endpoint (GET /queries) to get the Query ID.
2. Executing the Query
Using the query id and any variables required you are ready to setup the payload for executing the query via the Execute Query endpoint:
Example POST /queries/execute
Payload
{
"id": "dfcee886-231d-4a9d-9bdd-857f74XXXXX",
"variables": {
"question_number": 5
}
}
Code Samples
- Python
- TypeScript
- Python (with wrapper)
nildb/secretvault_python/nildb_api.py
loading...
const queryCredentials = async (
nodeName: NodeName,
query: string,
service?: string
): Promise<Credential[]> => {
const node = config[nodeName];
try {
const response = await fetch(`${node.url}/queries/execute`, {
method: 'POST',
headers: {
Authorization: `Bearer ${node.jwt}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
id: query,
variables: {
service: service,
},
}),
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const result = (await response.json()) as NodeResponse<Credential[]>;
return result.data || [];
} catch (error) {
console.error(`Error reading advanced credentials from ${nodeName}:`, error);
return [];
}
};