Skip to content

Extension API

What an extension reads and writes: live queries, mutations, metadata and its own translations — and the small, scoped GraphQL schema they run against. Every operation runs as one extension, for one business, beside one subject.

AuthAttributed by the hostScopeOne business, one subject
Endpoint
https://go.sessions.website/@<handle>/api/graphql/extensions
Scope
One business, one subject
Auth
Attributed by the host

Live queries

A live query is a GraphQL query you ship with a target. Sessions stores it with each version, runs it for you, and runs it again as the data changes — then hands your module the result as api.query.

Write it in a .graphql file and name it with query beside the target in sessions.extension.json. It is validated against this schema on every build, and pushed with the version.

Sessions runs it as the viewer, beside the target’s subject (session is the session the target renders beside), before your module renders. It runs it again after every api.mutate, and whenever the page refreshes its own data — so what you show is never stale.

api.query is a signal: read .value, or .subscribe to it; in Preact or React, useQuery() renders again with each new result. A target without a live query gets {}.

sessions types writes SessionNoteQuery.graphql.d.ts beside the query, so useQuery<SessionNoteQueryData>() is typed from the query itself.
SessionNoteQuery.graphql
# SessionNoteQuery.graphql — named by `query` in sessions.extension.json.
query SessionNote {
  extension {
    target
  }
  session {
    id
    startAt
    activity {
      name
      type
    }
    note: metadata(name: "app.studio-notes.note") {
      value
    }
  }
  viewer {
    isStaff
  }
}

Mutations

On business targets, api.mutate(document, {variables}) runs a mutation against this schema as the signed-in staff member, attributed to your extension. Public targets are read-only: their API has no mutate, and the server refuses a mutation from one.

Import the mutation from its .graphql file. The build validates it, and the generated types check your variables and type result.data. A string of GraphQL works too, untyped.

A mutation fails in two ways: GraphQL errors in result.errors, and the mutation’s own errors list (setMetadata { errors { field message } }). Check both, and tell the person with api.ui.toast(message, {tone: 'critical'}).

Don’t patch your state after a mutation: when it settles, Sessions re-runs the live query and api.query catches up on its own.

business.tsx
import saveNote from './SaveNoteMutation.graphql';

// Business targets only: `api.mutate` does not exist on public ones.
const result = await api.mutate(saveNote, {
  variables: {owner: {id: api.session.id}, value: note},
});

// Two kinds of failure: GraphQL errors, and the mutation's own errors list.
const message =
  result.errors?.[0]?.message ?? result.data?.setMetadata.errors[0]?.message;
if (message) api.ui.toast(message, {tone: 'critical'});

// No need to update anything: Sessions re-runs the live query, and
// api.query catches up on its own.

Metadata

Metadata is where an app keeps its data on Sessions’ records: named values on a session or an activity, written with setMetadata and removed with deleteMetadata.

Names are reverse DNS. Your app’s are app.<your handle>.… — app.studio-notes.note. Sessions’ own start with website.sessions. — website.sessions.spotify.playlist.id is the playlist Sessions shows on a session.

Read a field with metadata(name:), which returns {name value values} — value for a single value, values for a list — or null when nothing is stored. On a session it falls back to the activity’s field of the same name, the way buyer pages read it.

A private app may only write names under its own app.<handle>. namespace. It reads the same names; a name it may not read comes back null. A default (Sessions-owned) app reads any name on a business target, and Sessions’ public names (website.sessions.… and the well-known sessions.… fields) plus its own on a public one. A default (Sessions-owned) app may write any name.
SessionNoteQuery.graphql
query SessionPlaylist {
  session {
    # One value, by its reverse-DNS name. Falls back to the activity's
    # field of the same name when the session stores none.
    note: metadata(name: "app.studio-notes.note") {
      value
    }
    # A list field: every value, in order.
    tags: metadata(name: "app.studio-notes.tags") {
      values
    }
    # Sessions' own names start with website.sessions. Only a default
    # (Sessions-owned) app reads them; for any other app this is null.
    spotify: metadata(name: "website.sessions.spotify.playlist.id") {
      value
    }
  }
}

Localization

Ship one translations/<locale>.json per language in the extension directory. The CLI pushes them with each version; Sessions hands the extension every locale’s strings, and api.localization.translate(key, replacements) resolves a key for the viewer.

Keys are dot paths into nested objects. {{name}} placeholders are filled from replacements (numbers are formatted for the locale). An object keyed by Intl.PluralRules categories — one, other, … — is a plural, chosen by replacements.count.

A key falls back from the exact locale (fr-CA) to its language (fr), then to en, then to the key itself — so a missing string is easy to spot rather than blank.

formatNumber, formatDate and formatCurrency format with Intl in the viewer’s locale. Pass the business’s timezone to formatDate to show the time where the session happens.

api.localization.locale is a signal: it changes when the viewer switches language, without a reload. useTranslate() renders again when it does.
translations/en.json
{
  "save": "Save",
  "playlist": {
    "connected": "Connected to {{service}}",
    "tracks": {
      "one": "{{count}} track",
      "other": "{{count}} tracks"
    }
  }
}

How requests are made

You never call the endpoint yourself: the host sends every request with an X-Sessions-Extension header naming the running instance and an X-Sessions-Extension-Subject header naming the subject, and the server re-derives what the instance may see.

The schema is scoped: one business, the one subject beside the target, the viewer (null for an anonymous buyer), and your extension’s own identity. There is no way to reach another business or another session.

Schema reference

Every type in the extension API.

Query object

The extension instance this operation runs as.

businessBusiness!

The business the extension is rendering for.

sessionSession

The session the extension renders beside. Set for the business.session.details.block and public.session.detail-list.row targets; null for a target with no session subject.

viewerViewer

The person looking at the extension. Null for an anonymous visitor on a public target; always set on an admin target.

Mutation object

Store one scalar metadata value on the session or activity the extension renders beside. An app may only write names under its own namespace, app.<app handle>.… — a default (Sessions-owned) app may write any name. Requires a staff viewer.

Arguments (3)
nameString!
valueString!
deleteMetadataDeleteMetadataResult!

Remove a metadata value the extension's app owns. Same namespace rule as setMetadata. Requires a staff viewer.

Arguments (2)
nameString!

Activity object

idID!
nameString!
typeString

The activity type, e.g. yoga, basketball, music.lesson.

One metadata field on the activity, by its reverse-DNS name. Null when none is stored, or when the app may not read the name — the same rule as Session.metadata.

Arguments (1)
nameString!

App object

idID!
handleString!
nameString!

AppExtension object

idID!
handleString!
nameString!

Business object

idID!
handleString!
nameString!
timezoneString!

IANA timezone identifier the business schedules in, e.g. America/Toronto.

urlURL!

The business's public page.

DeleteMetadataResult object

deletedBoolean!

EntityRef input object

A reference to another node by its id.

idID!

ExtensionContext object

Which extension is asking, and where it is rendering.

idID!

The UIExtensionInstance id the host rendered.

targetUIExtensionTarget!
apiVersionString!

The extension API version the running module declared.

appApp!
extensionAppExtension!

MetadataField object

A metadata field stored on a resource under one reverse-DNS name. A scalar field has one value; a list field has several, in order.

nameString!
valueString

The first (for a scalar field, the only) stored value.

values[String!]!

Every stored value, in order.

OperationError object

fieldString

The argument that caused the error, or null for the operation as a whole.

messageString!

Session object

idID!
startAtDateTime
endAtDateTime
isCancelledBoolean!
activityActivity!

One metadata field on the session, by its reverse-DNS name. Falls back to the activity's field of the same name when the session stores nothing under it, the way the buyer-facing surfaces read it. Null when neither does — and when the app may not read the name:

  • an app reads its own app.<app handle>.… names on every target;
  • a default (Sessions-owned) app also reads any name on a business.*

target, and Sessions' public names (website.sessions.… and the well-known sessions.… fields) on a public.* target.

A legacy sessions.website.… name reads the website.sessions.… row.

Arguments (1)
nameString!

The music playlist attached to the session, resolved from Sessions' own website.sessions.<service>.playlist.id metadata (spotify, apple-music, youtube; the first that holds a usable value wins). Null when none does. Selecting name looks the playlist up on the streaming service (cached, best-effort).

urlURL!

The buyer-facing session page.

SessionPlaylist object

A music playlist a business attached to a session.

urlURL!

The playlist's public page on the streaming service.

nameString

The playlist's display name, looked up on the service. Null when it is private, deleted, or the lookup fails — fall back to a generic label.

SessionPlaylistService enum

The external music streaming service hosting a session playlist.

spotify
appleMusic
youtube

SetMetadataResult object

valueString

Viewer object

idID!
nameString!
isStaffBoolean!

Whether the viewer is on the business's staff.

Scalars

Boolean

The Boolean scalar type represents true or false.

DateTime

An ISO 8601 date-time string, e.g. 2026-09-24T18:30:00.000Z.

ID

The ID scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as "4") or integer (such as 4) input value will be accepted as an ID.

String

The String scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.

UIExtensionTarget

Where in the Sessions UI an extension renders, e.g. business.session.details.block or public.session.detail-list.row — the names an extension declares in sessions.extension.json.

URL

An absolute http(s) URL.