Notion: Query sessions
Notion sessions.querySessions: arguments, response, policy and SDK examples.
← Sessions operations · Get started
Operation notion.query_sessions
Provider route: POST /v1/sessions/query. Alter supplies the connection’s credentials and routing.
Call through Alter
Section titled “Call through Alter”Install @alter-ai/sdk @alter-ai/notion with npm, or alter-sdk-notion with pip. Supply your connected customer’s grant ID and the arguments described below.
import { App } from "@alter-ai/sdk";import { NotionIntegration } from "@alter-ai/notion";
async function execute(input: Parameters<NotionIntegration["sessions"]["querySessions"]>[0]) { const app = new App({ apiKey: process.env.ALTER_API_KEY! }); try { const provider = new NotionIntegration(app, { grantId: process.env.PROVIDER_GRANT_ID! }); const call = await provider.sessions.querySessions(input); const result = await call.wait(); return result.bodyJson(); } finally { await app.close(); }}import osfrom alter_sdk import Appfrom alter_sdk_notion import NotionIntegration
async def execute(arguments): async with App(api_key=os.environ["ALTER_API_KEY"]) as app: provider = NotionIntegration(app, {"grant_id": os.environ["PROVIDER_GRANT_ID"]}) call = await provider.sessions.query_sessions(arguments) result = await call.wait() return result.body_json()| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: not allowed |
body | object | Required within parent | Additional keys: not allowed |
body.filter | JSON | Optional | A session property filter, or an and/or compound filter nested up to two levels deep. |
body.filter (oneOf 1) | Model | Alternative | Expand Query sessions — request body — body / filter / property: id |
body.filter (oneOf 2) | Model | Alternative | Expand Query sessions — request body — body / filter / property: agent id |
body.filter (oneOf 3) | Model | Alternative | Expand Query sessions — request body — body / filter / property: status |
body.filter (oneOf 4) | Model | Alternative | Expand Query sessions — request body — body / filter / property: created at, updated at |
body.filter (oneOf 5) | object | Alternative | Additional keys: not allowed |
body.filter (oneOf 5).and | array | Required within parent | Return sessions that match every child filter. Maximum items: 100 |
body.filter (oneOf 5).and[] | Model | Each item | Expand Query sessions — request body — body filter or or item |
body.filter (oneOf 6) | object | Alternative | Additional keys: not allowed |
body.filter (oneOf 6).or | array | Required within parent | Return sessions that match any child filter. Maximum items: 100 |
body.filter (oneOf 6).or[] | Model | Each item | Expand Query sessions — request body — body filter or or item |
body.page_size | integer | Optional | The number of sessions to return. Maximum: 100. Maximum: 100 Minimum: 1 |
body.query | string | Optional | A case-insensitive substring search over session titles. Maximum length: 2000 |
body.sorts | array | Optional | Ordered sort precedence. Defaults to updated_at descending. Maximum items: 2 Minimum items: 1 |
body.sorts[] | object | Each item | Additional keys: not allowed |
body.sorts[].direction | string | Required within parent | One of: `ascending`, `descending` One of: ascending, descending |
body.sorts[].property | string | Required within parent | One of: `created_at`, `updated_at` One of: created_at, updated_at |
body.start_cursor | string | Optional | The continuation cursor returned by the previous page. |
Referenced models: Query sessions — request body — body / filter / property: agent id, Query sessions — request body — body / filter / property: id, Query sessions — request body — body filter or or item, Query sessions — request body — body / filter / property: status, Query sessions — request body — body / filter / property: created at, updated at
Response
Section titled “Response”Response media type: application/json. The table describes the pinned successful response. Referenced models link to their complete fields.
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: allowed |
has_more | boolean | Required within parent | Whether more session candidates remain after this bounded scan. |
next_cursor | JSON | Required within parent | Pass this cursor as start_cursor when has_more is true, even when results is empty. |
next_cursor (anyOf 1) | string | Alternative | |
next_cursor (anyOf 2) | null | Alternative | |
object | string | Required within parent | Always `list` Must equal: list |
results | array | Required within parent | Sessions found in this bounded scan. Access filtering can leave this array empty while has_more is true. Maximum items: 100 |
results[] | object | Each item | Additional keys: allowed |
results[].agent_id | string | Required within parent | |
results[].agent_version | JSON | Required within parent | |
results[].agent_version (anyOf 1) | object | Alternative | Additional keys: allowed |
results[].agent_version (anyOf 1).id | string | Required within parent | |
results[].agent_version (anyOf 1).number | JSON | Required within parent | |
results[].agent_version (anyOf 1).number (anyOf 1) | integer | Alternative | Minimum: 1 |
results[].agent_version (anyOf 1).number (anyOf 2) | string | Alternative | Pattern: ^-?[0-9]+(?:.[0-9]+)?(?:[eE][+-]?[0-9]+)?$ |
results[].agent_version (anyOf 1).published_at | string | Required within parent | Format: date-time |
results[].agent_version (anyOf 2) | null | Alternative | |
results[].chat_user_emails | JSON | Optional | |
results[].chat_user_emails (anyOf 1) | array | Alternative | |
results[].chat_user_emails (anyOf 1)[] | string | Each item | |
results[].chat_user_emails (anyOf 2) | null | Alternative | |
results[].created_at | string | Required within parent | Format: date-time |
results[].created_by | object | Required within parent | Additional keys: allowed |
results[].created_by.id | string | Required within parent | |
results[].created_by.type | string | Required within parent | One of: `user`, `bot` Known values: user, bot |
results[].credits_used | JSON | Optional | Premium AI credits this session consumed. Reported with at most two decimal places, rounded down. |
results[].credits_used (anyOf 1) | JSON | Alternative | |
results[].credits_used (anyOf 1) (anyOf 1) | number | Alternative | Minimum: 0 |
results[].credits_used (anyOf 1) (anyOf 2) | string | Alternative | Pattern: ^-?[0-9]+(?:.[0-9]+)?(?:[eE][+-]?[0-9]+)?$ |
results[].credits_used (anyOf 2) | null | Alternative | |
results[].error | object | Optional | Additional keys: allowed |
results[].error.code | string | Required within parent | |
results[].error.message | string | Required within parent | |
results[].error.retryable | boolean | Required within parent | |
results[].id | string | Required within parent | |
results[].message_count | JSON | Optional | |
results[].message_count (anyOf 1) | JSON | Alternative | |
results[].message_count (anyOf 1) (anyOf 1) | integer | Alternative | Minimum: 0 |
results[].message_count (anyOf 1) (anyOf 2) | string | Alternative | Pattern: ^-?[0-9]+(?:.[0-9]+)?(?:[eE][+-]?[0-9]+)?$ |
results[].message_count (anyOf 2) | null | Alternative | |
results[].models | JSON | Required within parent | |
results[].models (anyOf 1) | object | Alternative | Additional keys: allowed |
results[].models (anyOf 1).type | string | Required within parent | Always `auto` Must equal: auto |
results[].models (anyOf 2) | object | Alternative | Additional keys: allowed |
results[].models (anyOf 2).ids | array | Required within parent | |
results[].models (anyOf 2).ids[] | JSON | Each item | |
results[].models (anyOf 2).ids[] (anyOf 1) | string | Alternative | |
results[].models (anyOf 2).ids[] (anyOf 2) | null | Alternative | |
results[].models (anyOf 2).type | string | Required within parent | Always `pinned` Must equal: pinned |
results[].object | string | Required within parent | Always `session` Must equal: session |
results[].required_actions | array | Optional | |
results[].required_actions[] | object | Each item | Additional keys: allowed |
results[].required_actions[].action_id | string | Required within parent | |
results[].required_actions[].options | array | Required within parent | Maximum items: 100 |
results[].required_actions[].options[] | object | Each item | Additional keys: allowed |
results[].required_actions[].options[].id | string | Required within parent | One of: `approve`, `reject` Known values: approve, reject |
results[].required_actions[].options[].label | string | Required within parent | |
results[].required_actions[].title | string | Required within parent | |
results[].runs_completed | JSON | Optional | |
results[].runs_completed (anyOf 1) | JSON | Alternative | |
results[].runs_completed (anyOf 1) (anyOf 1) | integer | Alternative | Minimum: 0 |
results[].runs_completed (anyOf 1) (anyOf 2) | string | Alternative | Pattern: ^-?[0-9]+(?:.[0-9]+)?(?:[eE][+-]?[0-9]+)?$ |
results[].runs_completed (anyOf 2) | null | Alternative | |
results[].status | string | Required within parent | One of: `queued`, `in_progress`, `requires_action`, `completed`, `failed`, `canceled`, `terminated` Known values: queued, in_progress, requires_action, completed, failed, canceled, terminated |
results[].title | string | Required within parent | |
results[].tool_call_count | JSON | Optional | |
results[].tool_call_count (anyOf 1) | JSON | Alternative | |
results[].tool_call_count (anyOf 1) (anyOf 1) | integer | Alternative | Minimum: 0 |
results[].tool_call_count (anyOf 1) (anyOf 2) | string | Alternative | Pattern: ^-?[0-9]+(?:.[0-9]+)?(?:[eE][+-]?[0-9]+)?$ |
results[].tool_call_count (anyOf 2) | null | Alternative | |
results[].tool_types | JSON | Optional | |
results[].tool_types (anyOf 1) | array | Alternative | |
results[].tool_types (anyOf 1)[] | string | Each item | |
results[].tool_types (anyOf 2) | null | Alternative | |
results[].trigger_type | string | Optional | |
results[].type_labels | JSON | Optional | |
results[].type_labels (anyOf 1) | array | Alternative | |
results[].type_labels (anyOf 1)[] | string | Each item | |
results[].type_labels (anyOf 2) | null | Alternative | |
results[].updated_at | string | Required within parent | Format: date-time |
session | object | Required within parent | Additional keys: allowed |
type | string | Required within parent | Always `session` Must equal: session |
Schemas
Section titled “Schemas”Query sessions — request body — body / filter / property: agent id
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: not allowed |
property | string | Required within parent | Filter sessions by agent_id. One of: agent_id |
string | object | Required within parent | An exact string comparison. Additional keys: not allowed |
string.equals | string | Required within parent | Return sessions with this exact value. |
Query sessions — request body — body / filter / property: id
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: not allowed |
property | string | Required within parent | Filter sessions by id. One of: id |
string | object | Required within parent | An exact string comparison. Additional keys: not allowed |
string.equals | string | Required within parent | Return sessions with this exact value. |
Query sessions — request body — body filter or or item
Referenced models: Query sessions — request body — body / filter / property: agent id, Query sessions — request body — body / filter / property: id, Query sessions — request body — body / filter / property: status, Query sessions — request body — body / filter / property: created at, updated at
Query sessions — request body — body / filter / property: status
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: not allowed |
property | string | Required within parent | Filter sessions by status. One of: status |
status | object | Required within parent | A session status comparison. Additional keys: not allowed |
status.equals | string | Optional | Return sessions with this status. One of: queued, in_progress, requires_action, completed, failed, canceled, terminated |
status.in | array | Optional | Return sessions with any of these statuses. Maximum items: 7 |
status.in[] | string | Each item | One of: queued, in_progress, requires_action, completed, failed, canceled, terminated |
Query sessions — request body — body / filter / property: created at, updated at
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: not allowed |
property | string | Required within parent | The session timestamp to compare. One of: created_at, updated_at |
timestamp | object | Required within parent | A timestamp range. Additional keys: not allowed |
timestamp.after | string | Optional | Return sessions after this time. Format: date-time |
timestamp.before | string | Optional | Return sessions before this time. Format: date-time |
timestamp.on_or_after | string | Optional | Return sessions at or after this time. Format: date-time |
timestamp.on_or_before | string | Optional | Return sessions at or before this time. Format: date-time |
Policy, approvals and errors
Section titled “Policy, approvals and errors”SDK function policy ID: notion.query_sessions. Catalog operation: query_sessions. Rules can name either ID; function rules distinguish managed calls and conservatively cover raw calls sharing the route. Existing grant permissions and policy rules apply. wait() returns an immediate result or waits for a required approval; it never approves the request itself. Persist the approval ID to resume after a restart.
Provider errors retain their response; JSON decoding raises ProviderAPIError for provider failures. ManagedOperationError identifies contract/input/retention errors. See error handling and provider-specific behavior. Sensitive input may be refused before approval storage. A decoding error never resubmits a write.
Pinned headers: {"Notion-Version": "2026-03-11"}