SQL

Query records and lists with SQL. Your workspace must be on the Enterprise plan in order to access this endpoint.

This endpoint is rate limited to 2 requests per second.

This endpoint is in beta. We will aim to avoid breaking changes, but small updates may be made as we roll out to more users.

Required scopes: record_permission:read, object_configuration:read.

Supported token levels: workspace, user.

post/v2/sql

Request

  • Base URL
    https://api.attio.com
  • URL
    https://api.attio.com/v2/sql
  • Auth
    OAuth 2
    Authorization code: https://app.attio.com/authorize
    Token URL: https://app.attio.com/oauth/token scopes: record_permission:read, object_configuration:read

Request body

sqlstring required

The SQL query to be executed. Use $name placeholders to reference values from parameters instead of inlining them into the query.

parametersobject

Named parameters referenced in the query using $name syntax. A maximum of 25 parameters can be provided. Each parameter must declare its type explicitly. Names must start with a letter or underscore, only contain letters, digits and underscores, and be at most 64 characters long. Compare against a list parameter with = ANY($name), not IN ($name), which does not type check. Read a field of a struct parameter with get_field($name, 'field').

Example request

{
  "sql": "SELECT * FROM companies WHERE (name = $name OR name = ANY($names)) AND created_at >= $since",
  "parameters": {
    "name": {
      "type": "string",
      "value": "Fundstack"
    },
    "since": {
      "type": "timestamp",
      "value": "2023-01-01T15:00:00.000000000Z"
    },
    "names": {
      "type": "list",
      "item_type": "string",
      "value": [
        "Fundstack",
        "Acme"
      ]
    }
  }
}

Response

Success

Example response

{
  "data": {
    "rows": [
      {
        "record_id": "bf071e1f-6035-429d-b874-d83ea64ea13b",
        "created_at": "2023-01-01T15:00:00.000000000Z",
        "name": "Fundstack",
        "created_by": {
          "type": "workspace-member",
          "id": "50cf242c-7fa3-4cad-87d0-75b1af71c57b"
        },
        "domains": [
          "fundstack.com"
        ]
      }
    ]
  }
}

Changes