SQL API
Run SQL queries in your data warehouse.
The SQL API runs queries against your data warehouse through an existing connection and returns the rows. It is the most direct way to get data out of CARTO, and the same endpoint that Workflows calls when you trigger one via API.
GET /v3/sql/{connectionName}/query
Run a query
POST /v3/sql/{connectionName}/query
Run a query (POST)
POST /v3/sql/{connectionName}/job
Create a job
GET /v3/sql/{connectionName}/job/{jobId}
Get a job
DELETE /v3/sql/{connectionName}/job/{jobId}
Cancel a job
GET /v3/sql/jobs
List jobs
Choosing an endpoint
Short, and you want it cached
GET /query
Cached for 1 year. Fastest for repeated reads
Too long for a URL, or must always hit the warehouse
POST /query
Never cached, so every request costs warehouse compute
Longer than 1 minute
POST /job
Runs asynchronously. Poll the job for its status
Synchronous requests time out after 1 minute. If a query might exceed that — a large CREATE TABLE, a heavy aggregation — create a job instead and poll it rather than retrying the synchronous call.
Results are capped at 200,000 rows.
About queryParameters and parameterized queries
sqlQuery: 'SELECT * FROM carto-demo-data.demo_tables.retail_stores WHERE storetype = @type AND revenue > @minRevenue'
queryParameters: { 'minRevenue': 100000, 'type': 'Supermarket' },sqlQuery: 'SELECT * FROM demo_db.public.import_retail_stores WHERE storetype = :2 AND revenue > :1'
queryParameters: [100000, "Supermarket"],sqlQuery: 'SELECT * FROM carto_demo_data.demo_tables.retail_stores WHERE storetype = $2 AND revenue > $1...'
queryParameters: [100000, "Supermarket"],Endpoints
Runs a SQL query and returns the result.
Times out after 1 minute. For longer queries, create a job instead.
An API Access Token or an OAuth Access Token, sent as
Authorization: Bearer <token>.
Name of the connection to use.
carto_dwThe SQL query, or the name of a named source.
SELECT * FROM carto-demo-data.demo_tables.airportsValues for the parameters in the query, as a JSON string. Named object on BigQuery, positional array on Snowflake, Redshift and PostgreSQL.
{"minRevenue": 100000, "type": "Supermarket"}API version. From 3.3, spatialDataColumn and spatialDataType replace
geo_column.
3.0Possible values: The query result.
The rows returned by the query, plus the schema of the result set. Responses are capped at 200,000 rows.
The request is malformed or a parameter failed validation.
The token is missing, malformed or expired.
The token doesn't grant access to this resource.
The resource doesn't exist.
The query took longer than the 1 minute timeout.
You went over the rate limit for this API.
The Maps and SQL APIs also return it when the connection already has as many queries running in the data warehouse as it allows. Retry once some of them finish.
GET /v3/sql/{connectionName}/query?q=text HTTP/1.1
Host: gcp-us-east1.api.carto.com
Authorization: Bearer YOUR_SECRET_TOKEN
Accept: */*
{
"rows": [
{
"name": "Madrid Barajas",
"geom": {
"type": "Point",
"coordinates": [
-3.56676,
40.47225
]
}
}
],
"schema": [
{
"name": "name",
"type": "string"
},
{
"name": "geom",
"type": "geometry"
}
]
}Same as the GET variant, for queries too long to fit in a URL.
This endpoint is not cached in CARTO's CDN, so every request reaches the data warehouse. Keep that in mind to avoid unnecessary compute cost.
An API Access Token or an OAuth Access Token, sent as
Authorization: Bearer <token>.
Name of the connection to use.
carto_dwThe SQL query, or the name of a named source.
Values for the parameters in the query. A named object on BigQuery, a positional array on Snowflake, Redshift and PostgreSQL.
The query result.
The rows returned by the query, plus the schema of the result set. Responses are capped at 200,000 rows.
The request is malformed or a parameter failed validation.
The token is missing, malformed or expired.
The token doesn't grant access to this resource.
The query took longer than the 1 minute timeout.
You went over the rate limit for this API.
The Maps and SQL APIs also return it when the connection already has as many queries running in the data warehouse as it allows. Retry once some of them finish.
POST /v3/sql/{connectionName}/query HTTP/1.1
Host: gcp-us-east1.api.carto.com
Authorization: Bearer YOUR_SECRET_TOKEN
Content-Type: application/json
Accept: */*
Content-Length: 79
{
"q": "SELECT * FROM carto-demo-data.demo_tables.airports",
"queryParameters": {}
}{
"rows": [
{
"name": "Madrid Barajas",
"geom": {
"type": "Point",
"coordinates": [
-3.56676,
40.47225
]
}
}
],
"schema": [
{
"name": "name",
"type": "string"
},
{
"name": "geom",
"type": "geometry"
}
]
}Runs a query asynchronously. Use this for queries that would exceed the 1 minute timeout of the synchronous endpoints.
Available for BigQuery, Snowflake, Redshift, PostgreSQL, Databricks (REST and SQL Warehouse), Oracle and CARTO Data Warehouse connections.
Poll GET /v3/sql/{connectionName}/job/{jobId} with the
returned externalId to follow the execution.
An API Access Token or an OAuth Access Token, sent as
Authorization: Bearer <token>.
Name of the connection to use.
carto_dwThe SQL query, or the name of a named source. Note this field is
query, not q.
Values for the parameters in the query. A named object on BigQuery, a positional array on Snowflake, Redshift and PostgreSQL.
Optional client identifier, recorded for metrics.
The job was created.
An asynchronous SQL job, as returned when it is created.
Use this to poll the job.
The request is malformed or a parameter failed validation.
The token is missing, malformed or expired.
The token doesn't grant access to this resource.
You went over the rate limit for this API.
The Maps and SQL APIs also return it when the connection already has as many queries running in the data warehouse as it allows. Retry once some of them finish.
POST /v3/sql/{connectionName}/job HTTP/1.1
Host: gcp-us-east1.api.carto.com
Authorization: Bearer YOUR_SECRET_TOKEN
Content-Type: application/json
Accept: */*
Content-Length: 177
{
"query": "CREATE TABLE your-project.your_dataset.airports_copy AS (SELECT * FROM carto-demo-data.demo_tables.airports)",
"queryParameters": {},
"metadata": {
"source": "nightly-etl"
}
}{
"externalId": "job_h8UWzpdzX0s2XAAXQd3rdWCdPUT9",
"accountId": "ac_jfakef5m",
"userId": "auth0|61164b7xxx77c006a259f53",
"connectionId": "5a32a0ea-555a-48dd-aeb1-8768aae8ef1c",
"connectionName": "carto_dw",
"providerId": "bigquery",
"metadata": {
"source": "nightly-etl"
},
"createdAt": "2026-07-30T16:10:35.732Z",
"query": "CREATE TABLE your-project.your_dataset.airports_copy AS (SELECT * FROM carto-demo-data.demo_tables.airports)",
"jobMetadata": {
"location": "US"
}
}Returns the current state of an asynchronous job.
An API Access Token or an OAuth Access Token, sent as
Authorization: Bearer <token>.
Name of the connection to use.
carto_dwThe job identifier.
job_h8UWzpdzX0s2XAAXQd3rdWCdPUT9The job.
The state of an asynchronous SQL job.
success, failure and cancelled are final states.
The token is missing, malformed or expired.
The token doesn't grant access to this resource.
The resource doesn't exist.
You went over the rate limit for this API.
The Maps and SQL APIs also return it when the connection already has as many queries running in the data warehouse as it allows. Retry once some of them finish.
GET /v3/sql/{connectionName}/job/{jobId} HTTP/1.1
Host: gcp-us-east1.api.carto.com
Authorization: Bearer YOUR_SECRET_TOKEN
Accept: */*
{
"jobId": "job_h8UWzpdzX0s2XAAXQd3rdWCdPUT9",
"connectionName": "carto_dw",
"providerId": "bigquery",
"query": "SELECT * FROM carto-demo-data.demo_tables.airports",
"status": "success",
"error": null,
"createdAt": "2026-07-30T16:10:35.732Z",
"jobMetadata": {
"location": "US"
},
"metadata": {}
}Cancels a running job. Returns no content on success.
An API Access Token or an OAuth Access Token, sent as
Authorization: Bearer <token>.
Name of the connection to use.
carto_dwThe job identifier.
job_h8UWzpdzX0s2XAAXQd3rdWCdPUT9The job was cancelled.
No content
The token is missing, malformed or expired.
The token doesn't grant access to this resource.
The resource doesn't exist.
You went over the rate limit for this API.
The Maps and SQL APIs also return it when the connection already has as many queries running in the data warehouse as it allows. Retry once some of them finish.
DELETE /v3/sql/{connectionName}/job/{jobId} HTTP/1.1
Host: gcp-us-east1.api.carto.com
Authorization: Bearer YOUR_SECRET_TOKEN
Accept: */*
No content
Lists the asynchronous jobs in your account.
Only user_id, created_since and client are accepted — any other query
parameter returns 400.
An API Access Token or an OAuth Access Token, sent as
Authorization: Bearer <token>.
Filter by user. Ignored when authenticating with an API Access Token, which is always scoped to its own user.
Only return jobs created after this date.
2026-07-01T00:00:00.000ZOptional client identifier, recorded for metrics.
The jobs.
A job as returned by the list endpoint. Note this shape uses state where
GET /v3/sql/{connectionName}/job/{jobId} uses status.
null until the job has been submitted to the warehouse.
null when the job hasn't failed.
The request is malformed or a parameter failed validation.
The token is missing, malformed or expired.
The token doesn't grant access to this resource.
You went over the rate limit for this API.
The Maps and SQL APIs also return it when the connection already has as many queries running in the data warehouse as it allows. Retry once some of them finish.
GET /v3/sql/jobs HTTP/1.1
Host: gcp-us-east1.api.carto.com
Authorization: Bearer YOUR_SECRET_TOKEN
Accept: */*
[
{
"externalId": "text",
"accountId": "text",
"userId": null,
"connectionId": "text",
"metadata": {
"ANY_ADDITIONAL_PROPERTY": "anything"
},
"createdAt": "2026-01-01T00:00:00.000Z",
"updatedAt": "2026-01-01T00:00:00.000Z",
"query": null,
"state": "pending",
"error": null,
"jobMetadata": {
"ANY_ADDITIONAL_PROPERTY": "anything"
},
"token": null
}
]Last updated
Was this helpful?
