Getting started
Run a read-only SQL query
Run a bounded query against PostgreSQL. The database enforces a read-only transaction; writes, including writes through functions, are rejected.
POST
/api/customer/v1/projects/{projectId}/databases/{databaseId}/queryPath parameters
| Name | Value |
|---|---|
projectId | Required resource ID from an earlier API response. |
databaseId | Required resource ID from an earlier API response. |
Request body
Send JSON with Content-Type: application/json. Nested fields and accepted values are listed in the schema.
| Field | Type | Required |
|---|---|---|
query | string | Yes |
params | JSON[] | No |
Full request schema
{
"type": "object",
"properties": {
"query": {
"type": "string",
"minLength": 1
},
"params": {
"type": "array",
"items": {}
}
},
"required": [
"query"
],
"additionalProperties": false
}Example request
Set HCODE_BASE_URL and HCODE_API_KEY as shown in Getting started. Replace resource variables with your own IDs.
curl --request POST "$HCODE_BASE_URL/api/customer/v1/projects/${PROJECT_ID}/databases/${DATABASE_ID}/query" \
--header "Authorization: Bearer $HCODE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"query": "SELECT 1 AS result"
}' Response
The JSON shape is defined in the response schema.
Response schema
{
"type": "object",
"properties": {
"success": {
"type": "boolean"
},
"rows": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": true
}
},
"fields": {
"type": "array",
"items": {}
},
"rowCount": {
"type": "integer"
},
"operationId": {
"type": "string"
},
"operations": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"status": {
"type": "string"
},
"href": {
"type": "string"
}
},
"required": [
"id",
"status",
"href"
]
}
}
},
"required": [],
"additionalProperties": true
}See errors and retries for failure responses.