API

Build a partner integration

Connect your service to an organization's objects and actions with an OAuth app, the SDK and a webhook.

A partner integration is a service of yours that works in a customer's organization without a person signed in: it defines the object types it needs, writes objects, runs actions and hears what changes through a webhook. It needs an OAuth app the organization makes for it and the SDK; every step below is a call you can also find in the API reference.

1. An OAuth app from the organization

An owner or admin of the organization opens the developer portal → OAuth apps and adds one, confirming it's them with a passkey or two-step sign-in. They choose:

  • Scopes: only ones they hold. An integration like this one needs ontology:write (its types), actions:admin and actions:run (its action), objects:read and objects:write, and tenant:write (its webhook).
  • Ceiling: the highest automation mode its action runs take. A run never goes further than the organization's own setting for that action in Tenant → Automation, and an action set to Manual only ever makes a proposal for a person.

They give you the client id (cli_…) and the client secret (si_cs_…), which the portal shows once. Keep the secret in your secret store. The app never holds more than the person who made it holds now, and stops working once they can no longer act in the organization.

2. A token by client credentials

Find the token endpoint in id.cactive.com.au's discovery document, https://id.cactive.com.au/.well-known/oauth-authorization-server (token_endpoint; grant_types_supported lists client_credentials), and trade the secret for a token:

curl -s https://id.cactive.com.au/oauth/token \
  -d grant_type=client_credentials \
  -d client_id=$CLIENT_ID -d client_secret=$CLIENT_SECRET \
  -d scope="ontology:write actions:admin actions:run objects:read objects:write tenant:write"

The answer is { access_token, token_type: "Bearer", expires_in: 900, scope }: a 15-minute token holding the scopes you asked for that the app may hold and its maker still holds. There is no refresh token; ask again with the secret. Rotating the secret or deleting the app ends its tokens within a minute.

3. The SDK over that token

fetchTransport takes a function for its token, so one transport asks for a new token as the old one runs out:

import { fetchTransport } from "@cactive/sdk"

let token: { value: string; until: number } | undefined
async function bearer() {
  if (token && Date.now() < token.until) return token.value
  const res = await fetch("https://id.cactive.com.au/oauth/token", {
    method: "POST",
    body: new URLSearchParams({ grant_type: "client_credentials", client_id: process.env.CLIENT_ID!, client_secret: process.env.CLIENT_SECRET! }),
  })
  const answer = await res.json()
  token = { value: answer.access_token, until: Date.now() + (answer.expires_in - 60) * 1000 }
  return token.value
}

const transport = fetchTransport({ baseUrl: "https://api.cactive.com.au", token: bearer })
const orgId = "org_123"

4. Your object type and action

import { actionTypesTypesPut, ontologyDefinitionsPut } from "@cactive/sdk/platform"

await ontologyDefinitionsPut(transport, {
  orgId, kind: "type", id: "parcel",
  body: { definition: { id: "parcel", apiName: "Parcel", label: "Parcel", plural: "Parcels", icon: "map-pin", color: "chart-2", title: "name",
    properties: { name: { type: "string", required: true, searchable: true }, status: { type: "string" } } } },
})

await actionTypesTypesPut(transport, {
  orgId, id: "deliver-parcel",
  body: { definition: { id: "deliver-parcel", label: "Deliver a parcel", availableOn: ["object:Parcel"],
    parameters: { parcel: { type: "objectRef", objectType: "Parcel" } },
    edits: [{ op: "modify", target: { $param: "parcel" }, values: { status: "delivered" } }],
    automation: { max: "auto", default: "auto" } } },
})

A breaking change to a published definition needs a proposal and its review (SDK); the command line's ontology push publishes the same definitions from files.

5. A webhook

import { postOrgWebhooks } from "@cactive/sdk/platform"

const { secret } = await postOrgWebhooks(transport, {
  orgId,
  body: { name: "Parcels", url: "https://partner.example.com/hooks", events: ["object.Parcel.*", "action.DeliverParcel.*", "object.create", "action.run"], enabled: true, format: "cloudevents" },
})

Store secret: it is shown once. Events are an object type's changes (object.Parcel.created, .updated, .deleted), an action's runs (action.DeliverParcel.proposed, .committed, .failed, …) and the organization's audit actions (object.create, action.run); patterns match without case, and prefix.* takes everything under it. Each delivery is a CloudEvents POST with x-cactive-signature: t=<unix seconds>,v1=<hex HMAC-SHA256 of "<t>.<raw body>">: check it with the secret before you trust the body. What reaches you is filtered to what the webhook's owner may export, as they are now. A webhook an app makes gets the audit actions; an admin who takes it in Tenant → Webhooks makes it theirs, and it then gets the catalogue events too. Subscriptions take up to a minute to start matching.

6. Objects and an action run

import { actionsActionDryRun, actionsActionRun, actionsRunsGet, objectsObjectCreate, objectsObjectGet } from "@cactive/sdk/platform"

const parcel = await objectsObjectCreate(transport, { orgId, type: "Parcel", body: { props: { name: "PX-1042", status: "ready" } } }, { idempotencyKey: "px-1042" })
const request = { params: { parcel: { type: "Parcel", id: parcel.id } } }

const plan = await actionsActionDryRun(transport, { orgId, action: "deliver-parcel", body: request })
const run = await actionsActionRun(transport, { orgId, action: "deliver-parcel", body: request }, { idempotencyKey: "px-1042-delivered" })
const state = await actionsRunsGet(transport, { orgId, run: run.run! })
const after = await objectsObjectGet(transport, { orgId, type: "Parcel", id: parcel.id })

The dry run says whether the run would go ahead, in which mode and whether it waits for sign-off, writing nothing. A run at a mode above what the organization, the action and your app's ceiling allow becomes a proposal or waits for approval; actionsRunsGet follows it, and your webhook hears action.DeliverParcel.committed when it lands. An idempotencyKey makes a retried request answer the first run. Everything the app does is audited as the app, never as the person who made it.