Skip to content

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.

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 os
from alter_sdk import App
from 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()
FieldTypePresenceDescription and constraints
$objectRootAdditional keys: not allowed
bodyobjectRequired within parentAdditional keys: not allowed
body.filterJSONOptionalA session property filter, or an and/or compound filter nested up to two levels deep.
body.filter (oneOf 1)ModelAlternativeExpand Query sessions — request body — body / filter / property: id
body.filter (oneOf 2)ModelAlternativeExpand Query sessions — request body — body / filter / property: agent id
body.filter (oneOf 3)ModelAlternativeExpand Query sessions — request body — body / filter / property: status
body.filter (oneOf 4)ModelAlternativeExpand Query sessions — request body — body / filter / property: created at, updated at
body.filter (oneOf 5)objectAlternativeAdditional keys: not allowed
body.filter (oneOf 5).andarrayRequired within parentReturn sessions that match every child filter.
Maximum items: 100
body.filter (oneOf 5).and[]ModelEach itemExpand Query sessions — request body — body filter or or item
body.filter (oneOf 6)objectAlternativeAdditional keys: not allowed
body.filter (oneOf 6).orarrayRequired within parentReturn sessions that match any child filter.
Maximum items: 100
body.filter (oneOf 6).or[]ModelEach itemExpand Query sessions — request body — body filter or or item
body.page_sizeintegerOptionalThe number of sessions to return. Maximum: 100.
Maximum: 100
Minimum: 1
body.querystringOptionalA case-insensitive substring search over session titles.
Maximum length: 2000
body.sortsarrayOptionalOrdered sort precedence. Defaults to updated_at descending.
Maximum items: 2
Minimum items: 1
body.sorts[]objectEach itemAdditional keys: not allowed
body.sorts[].directionstringRequired within parentOne of: `ascending`, `descending`
One of: ascending, descending
body.sorts[].propertystringRequired within parentOne of: `created_at`, `updated_at`
One of: created_at, updated_at
body.start_cursorstringOptionalThe 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 media type: application/json. The table describes the pinned successful response. Referenced models link to their complete fields.

FieldTypePresenceDescription and constraints
$objectRootAdditional keys: allowed
has_morebooleanRequired within parentWhether more session candidates remain after this bounded scan.
next_cursorJSONRequired within parentPass this cursor as start_cursor when has_more is true, even when results is empty.
next_cursor (anyOf 1)stringAlternative
next_cursor (anyOf 2)nullAlternative
objectstringRequired within parentAlways `list`
Must equal: list
resultsarrayRequired within parentSessions found in this bounded scan. Access filtering can leave this array empty while has_more is true.
Maximum items: 100
results[]objectEach itemAdditional keys: allowed
results[].agent_idstringRequired within parent
results[].agent_versionJSONRequired within parent
results[].agent_version (anyOf 1)objectAlternativeAdditional keys: allowed
results[].agent_version (anyOf 1).idstringRequired within parent
results[].agent_version (anyOf 1).numberJSONRequired within parent
results[].agent_version (anyOf 1).number (anyOf 1)integerAlternativeMinimum: 1
results[].agent_version (anyOf 1).number (anyOf 2)stringAlternativePattern: ^-?[0-9]+(?:.[0-9]+)?(?:[eE][+-]?[0-9]+)?$
results[].agent_version (anyOf 1).published_atstringRequired within parentFormat: date-time
results[].agent_version (anyOf 2)nullAlternative
results[].chat_user_emailsJSONOptional
results[].chat_user_emails (anyOf 1)arrayAlternative
results[].chat_user_emails (anyOf 1)[]stringEach item
results[].chat_user_emails (anyOf 2)nullAlternative
results[].created_atstringRequired within parentFormat: date-time
results[].created_byobjectRequired within parentAdditional keys: allowed
results[].created_by.idstringRequired within parent
results[].created_by.typestringRequired within parentOne of: `user`, `bot`
Known values: user, bot
results[].credits_usedJSONOptionalPremium AI credits this session consumed. Reported with at most two decimal places, rounded down.
results[].credits_used (anyOf 1)JSONAlternative
results[].credits_used (anyOf 1) (anyOf 1)numberAlternativeMinimum: 0
results[].credits_used (anyOf 1) (anyOf 2)stringAlternativePattern: ^-?[0-9]+(?:.[0-9]+)?(?:[eE][+-]?[0-9]+)?$
results[].credits_used (anyOf 2)nullAlternative
results[].errorobjectOptionalAdditional keys: allowed
results[].error.codestringRequired within parent
results[].error.messagestringRequired within parent
results[].error.retryablebooleanRequired within parent
results[].idstringRequired within parent
results[].message_countJSONOptional
results[].message_count (anyOf 1)JSONAlternative
results[].message_count (anyOf 1) (anyOf 1)integerAlternativeMinimum: 0
results[].message_count (anyOf 1) (anyOf 2)stringAlternativePattern: ^-?[0-9]+(?:.[0-9]+)?(?:[eE][+-]?[0-9]+)?$
results[].message_count (anyOf 2)nullAlternative
results[].modelsJSONRequired within parent
results[].models (anyOf 1)objectAlternativeAdditional keys: allowed
results[].models (anyOf 1).typestringRequired within parentAlways `auto`
Must equal: auto
results[].models (anyOf 2)objectAlternativeAdditional keys: allowed
results[].models (anyOf 2).idsarrayRequired within parent
results[].models (anyOf 2).ids[]JSONEach item
results[].models (anyOf 2).ids[] (anyOf 1)stringAlternative
results[].models (anyOf 2).ids[] (anyOf 2)nullAlternative
results[].models (anyOf 2).typestringRequired within parentAlways `pinned`
Must equal: pinned
results[].objectstringRequired within parentAlways `session`
Must equal: session
results[].required_actionsarrayOptional
results[].required_actions[]objectEach itemAdditional keys: allowed
results[].required_actions[].action_idstringRequired within parent
results[].required_actions[].optionsarrayRequired within parentMaximum items: 100
results[].required_actions[].options[]objectEach itemAdditional keys: allowed
results[].required_actions[].options[].idstringRequired within parentOne of: `approve`, `reject`
Known values: approve, reject
results[].required_actions[].options[].labelstringRequired within parent
results[].required_actions[].titlestringRequired within parent
results[].runs_completedJSONOptional
results[].runs_completed (anyOf 1)JSONAlternative
results[].runs_completed (anyOf 1) (anyOf 1)integerAlternativeMinimum: 0
results[].runs_completed (anyOf 1) (anyOf 2)stringAlternativePattern: ^-?[0-9]+(?:.[0-9]+)?(?:[eE][+-]?[0-9]+)?$
results[].runs_completed (anyOf 2)nullAlternative
results[].statusstringRequired within parentOne of: `queued`, `in_progress`, `requires_action`, `completed`, `failed`, `canceled`, `terminated`
Known values: queued, in_progress, requires_action, completed, failed, canceled, terminated
results[].titlestringRequired within parent
results[].tool_call_countJSONOptional
results[].tool_call_count (anyOf 1)JSONAlternative
results[].tool_call_count (anyOf 1) (anyOf 1)integerAlternativeMinimum: 0
results[].tool_call_count (anyOf 1) (anyOf 2)stringAlternativePattern: ^-?[0-9]+(?:.[0-9]+)?(?:[eE][+-]?[0-9]+)?$
results[].tool_call_count (anyOf 2)nullAlternative
results[].tool_typesJSONOptional
results[].tool_types (anyOf 1)arrayAlternative
results[].tool_types (anyOf 1)[]stringEach item
results[].tool_types (anyOf 2)nullAlternative
results[].trigger_typestringOptional
results[].type_labelsJSONOptional
results[].type_labels (anyOf 1)arrayAlternative
results[].type_labels (anyOf 1)[]stringEach item
results[].type_labels (anyOf 2)nullAlternative
results[].updated_atstringRequired within parentFormat: date-time
sessionobjectRequired within parentAdditional keys: allowed
typestringRequired within parentAlways `session`
Must equal: session
Query sessions — request body — body / filter / property: agent id
FieldTypePresenceDescription and constraints
$objectRootAdditional keys: not allowed
propertystringRequired within parentFilter sessions by agent_id.
One of: agent_id
stringobjectRequired within parentAn exact string comparison.
Additional keys: not allowed
string.equalsstringRequired within parentReturn sessions with this exact value.
Query sessions — request body — body / filter / property: id
FieldTypePresenceDescription and constraints
$objectRootAdditional keys: not allowed
propertystringRequired within parentFilter sessions by id.
One of: id
stringobjectRequired within parentAn exact string comparison.
Additional keys: not allowed
string.equalsstringRequired within parentReturn sessions with this exact value.
Query sessions — request body — body filter or or item
FieldTypePresenceDescription and constraints
$JSONRoot
$ (oneOf 1)ModelAlternativeExpand Query sessions — request body — body / filter / property: id
$ (oneOf 2)ModelAlternativeExpand Query sessions — request body — body / filter / property: agent id
$ (oneOf 3)ModelAlternativeExpand Query sessions — request body — body / filter / property: status
$ (oneOf 4)ModelAlternativeExpand Query sessions — request body — body / filter / property: created at, updated at
$ (oneOf 5)objectAlternativeAdditional keys: not allowed
$ (oneOf 5).andarrayRequired within parentReturn sessions that match every child filter.
Maximum items: 100
$ (oneOf 5).and[]JSONEach item
$ (oneOf 5).and[] (oneOf 1)ModelAlternativeExpand Query sessions — request body — body / filter / property: id
$ (oneOf 5).and[] (oneOf 2)ModelAlternativeExpand Query sessions — request body — body / filter / property: agent id
$ (oneOf 5).and[] (oneOf 3)ModelAlternativeExpand Query sessions — request body — body / filter / property: status
$ (oneOf 5).and[] (oneOf 4)ModelAlternativeExpand Query sessions — request body — body / filter / property: created at, updated at
$ (oneOf 6)objectAlternativeAdditional keys: not allowed
$ (oneOf 6).orarrayRequired within parentReturn sessions that match any child filter.
Maximum items: 100
$ (oneOf 6).or[]JSONEach item
$ (oneOf 6).or[] (oneOf 1)ModelAlternativeExpand Query sessions — request body — body / filter / property: id
$ (oneOf 6).or[] (oneOf 2)ModelAlternativeExpand Query sessions — request body — body / filter / property: agent id
$ (oneOf 6).or[] (oneOf 3)ModelAlternativeExpand Query sessions — request body — body / filter / property: status
$ (oneOf 6).or[] (oneOf 4)ModelAlternativeExpand Query sessions — request body — body / filter / property: created at, updated at

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
FieldTypePresenceDescription and constraints
$objectRootAdditional keys: not allowed
propertystringRequired within parentFilter sessions by status.
One of: status
statusobjectRequired within parentA session status comparison.
Additional keys: not allowed
status.equalsstringOptionalReturn sessions with this status.
One of: queued, in_progress, requires_action, completed, failed, canceled, terminated
status.inarrayOptionalReturn sessions with any of these statuses.
Maximum items: 7
status.in[]stringEach itemOne of: queued, in_progress, requires_action, completed, failed, canceled, terminated
Query sessions — request body — body / filter / property: created at, updated at
FieldTypePresenceDescription and constraints
$objectRootAdditional keys: not allowed
propertystringRequired within parentThe session timestamp to compare.
One of: created_at, updated_at
timestampobjectRequired within parentA timestamp range.
Additional keys: not allowed
timestamp.afterstringOptionalReturn sessions after this time.
Format: date-time
timestamp.beforestringOptionalReturn sessions before this time.
Format: date-time
timestamp.on_or_afterstringOptionalReturn sessions at or after this time.
Format: date-time
timestamp.on_or_beforestringOptionalReturn sessions at or before this time.
Format: date-time

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"}

Official provider source

Report an issue with this page

Necessary

Required for sign-in, security, authorization, and remembering your choices.

Always active

Analytics

Helps us understand which product and documentation features are useful.

Performance diagnostics

Uses performance tracing and privacy-masked session replay to diagnose problems.

You can change these choices at any time from Cookie settings.