Observability API
Count, group, and chart your solution's Record data from code with Solution Metrics.
The Observability API provides Solution Metrics: values, breakdowns, and trends calculated from your tenant's Record data. Use it from solution code that powers dashboards, reports, or alerts. For example, scheduled code can count each day's new Records and raise an alert above a threshold.
The API returns data, not charts. For ready-made dashboards in the Console, see Metrics.
What you can do
- Calculate single values, tables, and pie-chart slices, such as Records by status.
- Build time series by minute, hour, day, week, or month, and histograms of numeric fields.
- Query an Object Type's Records, attachment metadata, or Record change history. Change history needs Audit Trail on the Object Type.
- List the fields found in a collection's recent data.
The reference also lists POST /metrics and POST /metrics/ai, which the Console uses for its runtime and AI Gateway dashboards. POST /logs and POST /traces are not implemented and return 501.
Base URL and reference
- API base URL:
https://observability.<tenant-id>.my.contextual.io/api/v1 - Swagger reference: Observability API reference
- Raw OpenAPI: openapi.json
Replace <tenant-id> with the tenant ID from your Tenant Workspace URL. The hostname identifies your tenant, so the x-org-id header is optional. If you send it, it must match the hostname.
The OpenAPI document uses a relative server, so set the API base URL as the server when you import it into an API client or AI tool.
Authentication and permissions
Send an access token from a tenant API Key in the Authorization: Bearer <access-token> header. To get one, see Get an access token.
Set the key's permissions on its Permissions tab, under Object data & action execution. Each query needs Read for the data it covers:
| Query | Required permission |
|---|---|
Records of one Object Type (coll_name: native-object:<type-id>) |
Read in that Object Type's row |
Attachment metadata (contextual:files) or Record change history (contextual:native-object-instances-history), limited to specific Object Types |
Read in the row of each of those Object Types |
Attachment metadata or Record change history without an Object Type limit; any other collection; or any coll_name_prefix query |
Read in the All Object Types row |
<type-id> is the Object Type's ID, as used in its Native Object API path, such as customers. Read in the All Object Types row covers every query above.
To limit attachment metadata or change history to specific Object Types, set ref.typeId, or add a where condition with = or IN on ref.typeId (attachments) or data.typeId (change history). For per-type access, a type condition in where must use the default AND mode; OR filters do not by themselves establish the required Object Type restriction. Schema discovery takes only coll_name, so it needs wildcard read for attachment metadata and Record change history. When the key cannot read a collection, the API returns 403.
Request and response details
- Metric queries use
POST /metrics/solution. Schema discovery usesPOST /metrics/solution/schema/discoverwith the body{"coll_name": "<collection>"}and returnsdb_name,coll_name,total_paths, and aschemalist of field paths and types. Both only read data. - Each metric query needs a source, a time range, and at least one
selectentry. Set the source withcoll_name, such asnative-object:<type-id>, orcoll_name_prefix, such asnative-object:for all Object Types. For the time range, sendlast, such as-7dorall, or bothfromandto. - By default, time ranges and buckets use the time of each Record change. To use creation dates, set
time_fieldtocreatedAt. - Set
outputtovalue,table(the default),pie,timeseries, orhistogram. The response containsoutput,data, andmeta.datais an object forvalueand an array of rows otherwise. - Record collections such as
native-object:<type-id>keep captured versions of each Record. Withoutdedup, a Record can count more than once, and earlier versions of deleted Records can still count. For current counts or status breakdowns, usededup. With"dedup": true, change-time queries select each Record's latest captured version within the time window;createdAtqueries include later updates to Records created in that window.dedupalso leaves out Records whose latest version is a delete. For current totals or status breakdowns across all captured Records, also set"last": "all". Change history has one entry per change, sodedupdoes not change it. - Results include only the data captured for your tenant. See Interpreting Solution Data.
- An invalid query returns
400with amessageand anerrorslist. A query that exceeds time or data limits also returns400; narrow the time range or source.
Example request
This request counts the captured Records of one Object Type that were created in the last 30 days, leaving out deleted Records:
curl --request POST "https://observability.<tenant-id>.my.contextual.io/api/v1/metrics/solution" \
--header "Authorization: Bearer <access-token>" \
--header "Content-Type: application/json" \
--data '{
"coll_name": "native-object:<type-id>",
"last": "-30d",
"time_field": "createdAt",
"dedup": true,
"output": "value",
"select": [{ "agg": "count", "alias": "created" }]
}'
Replace <tenant-id>, <access-token>, and <type-id> as described above. A successful response returns 200 with the count in data.created.