Skip to content

Declarative integrations

A plug-in that only calls a vendor's API and reshapes the answer needs no container. Name the hosts it calls and give each endpoint a request and a map in place of a handler: Initiative makes the call with the connection's credential, and maps the answer itself. The plug-in has no service block, no image and nothing to run, and its listing registers it as declarative. It may still keep values on Initiative's items, which its webhook events, schedules and actions write and its fields and parts show.

// src/plugin.ts
import { definePlugin, defineEndpoint } from "initiative-plugin-sdk/manifest";

export const openIssues = defineEndpoint({
  direction: "read",
  label: { en: "Open issues" },
  params: { repo: { type: "string", label: { en: "Repository" }, required: true } },
  requires: { all_of: ["account"] },
  returns: { titles: { type: "string", list: true }, total: "int" },
  request: {
    method: "GET",
    url: '"https://api.tracker.example/repos/" & params.repo & "/issues"',
    query: { state: '"open"' },
    connection: "account",
  },
  map: '{"titles": response.body.title[], "total": $count(response.body)}',
});

export default definePlugin({
  publicId: "acme.tracker",
  uid: "K7M2QX8N4TVB9C",
  name: "Acme Tracker",
  hosts: ["api.tracker.example"],
  connections: {
    account: {
      scope: "interactive",
      label: { en: "Your account" },
      fields: [],
      flow: {
        type: "oauth2",
        authorize_url: "https://tracker.example/oauth/authorize",
        token_url: "https://tracker.example/oauth/token",
        client_id: "{vendor.client_id}",
      },
    },
  },
  vendor: { fields: [{ key: "client_id", type: "string", required: true, label: { en: "Client id" } }] },
  endpoints: { "open-issues": openIssues },
  listing: { publisher: "acme", summary: "Your tracker's issues.", avatar: "assets/avatar.png", version: "1.0.0" },
});
// test/open-issues.test.ts
import { expect, it } from "vitest";
import { runEndpoint } from "initiative-plugin-sdk/testing";
import plugin from "../src/plugin.js";
import issues from "./fixtures/issues.json" with { type: "json" };

it("lists a repository's open issues", async () => {
  const run = await runEndpoint(plugin, "open-issues", {
    params: { repo: "acme/web" },
    now: "2026-10-01T12:00:00Z",
    responses: [{ status: 200, body: issues }],
  });
  expect(run.requests).toEqual([
    {
      method: "GET",
      url: "https://api.tracker.example/repos/acme/web/issues?state=open",
      headers: {},
      connection: "account",
    },
  ]);
  expect(run).toMatchObject({ result: { titles: ["Broken build"], total: 1 } });
});
  • Every expression is JSONata, standard, with no functions added: the URL, each query parameter and header, the body or a GraphQL request's variables, and the map. An expression reads params, connection (the non-secret fields of the connection its request names), connections (on an endpoint, each connection its requires names that the call has, by id: connections.workspace.owner), now, and once a call has been answered response (status, headers, body). Every expression also reads settings, the install's settings by key, and aliases, each unique setting's earlier values. build parses every one and fails with its place in the manifest when one does not parse.
  • Each evaluation is bounded by the contract's CAPS.expressionTimeMs, CAPS.expressionDepth and CAPS.expressionOutputBytes; past one, or on an error, the call answers unavailable: mapping-failed. evaluate from initiative-plugin-sdk/testing runs an expression within the same bounds.
  • Credentials never enter an expression. Initiative adds the one the request's connection names, as auth says: Authorization: Bearer <token> unless auth: { header, prefix } says otherwise. Every address must be https on one of hosts, exact or with one leading *. label. A request or step naming an interactive connection for every call names it in the endpoint's requires too, and is on no endpoint whose actors include installation, or build fails: a call made as the installation has no member's credential. A call made as a member carries a static connection's credential only when requires names it, and is refused otherwise.
  • A connection per actor. A read's or write's request or step may name one connection for each of the endpoint's actors in place of one for every call, so a call made as the member carries the member's own credential and one made as the installation the community's:
export const comment = defineEndpoint({
  direction: "write",
  actors: ["member", "installation"],
  params: {
    number: { type: "int", label: { en: "Issue" }, required: true },
    text: { type: "string", label: { en: "Comment" }, required: true },
  },
  returns: { id: "int" },
  request: {
    method: "POST",
    url: '"https://api.tracker.example/issues/" & params.number & "/comments"',
    body: '{"body": params.text}',
    connection: { member: "account", installation: "workspace" },
  },
  map: '{"id": response.body.id}',
});

member names an interactive connection and installation a static one, for exactly the actors the endpoint declares. The member's needs no requires: a call made as the member requires it. An expression's connection holds the fields of the one the call carries. - steps in place of request makes up to three calls in order; each reads the earlier ones as steps.<name>, and so does the map. - paging on a request reads more pages before the map runs: page_number, link_header or cursor, each with max_pages (at most 10) and on_limit, truncate or refuse. - Errors. 401 and 403 answer unavailable: not-authorized, 404 not-found, other 4xx invalid, and 429, 3xx and 5xx are transient. errors rows match a status (404 or "4xx") and an optional when, such as a GraphQL error inside a 200, to a code the endpoint declares in unavailable, or to transient. A map may answer {"unavailable": "<code>"} itself. - Connections take a declarative after_connect (a request or up to three steps, a map to {values, account_label} or {choices}, and refuse_when with its code, which read each step as steps.<name>) and a health check run on an interval. Webhooks take events, each mapping a delivery to one of the plug-in's emissions, changes to its values, or both, and status rows that set a connection's state; a delivery may be routed by a header instead of a body path. - Scopes are read scopes alone, at the manifest's top level, and validateManifest refuses any other: a declarative plug-in keeps its own values on items it can read, and does not call Initiative. Initiative keeps its values only on items those scopes read, such as tasks with projects:read. - Values are written from a write expression: Initiative makes the changes it answers, as the install. A change sets values by key, {"set": {"<key>": <value>}}, the shape of client.metadata.set: a null removes its key, and every value is held to the metadata caps. A list field's value is its whole list of elements; its elements change by their ref with {"upsert": {"<key>": [<element>]}}, which adds each element or merges it into the one with its ref (the properties it gives replace that element's, the rest stay, and its state merges by facet, so a write that knows one fact changes that fact alone), and {"remove": {"<key>": ["<ref>"]}}. A change gives at least one of set, upsert and remove, and changes each key with only one. A targeted change adds its target: {"kind": "task", "id": 7} for one item, {"install": true} for the install, or {"holding": {"key": "<key>", "value": "<text>"}} for every item on which the install holds that value under that key (a number or a boolean as JSON writes it, a list element by its ref). A target the install cannot read is skipped, one write answers at most 100 targeted changes (CAPS.writeTargets), and a write answering nothing changes nothing. - An event row's write, beside its emit and map or in their place, answers targeted changes from headers, payload, connection, now, settings and aliases. The first row whose when holds applies, its emission and its write both. - An action names an endpoint, a write, or both. The endpoint may be a read, fetching what the write keeps, or a write that changes something at the vendor. Initiative makes the endpoint's call with the params the reader answered, on the credential its actors say, its expressions also reading item ({kind, id, title}) and element (the ref of the list element it was run from, if any), then the one change write answers from item, held (the install's values on the item), result (the endpoint's mapped answer), params, element, settings, aliases and now. - A schedule makes a read as the installation on an interval: endpoint names a read endpoint whose actors include installation, params answers its params from since (when the schedule last succeeded, or null), now, connection, settings and aliases, and write answers targeted changes from result, since, now, settings and aliases. Its id is none of the plug-in's connections': Initiative keys connection health checks by connection id.

schedules: {
  sync: {
    every: "1h",
    endpoint: "updated-issues", // returns numbers: int list, states: string list
    params: '{"since": since}',
    write:
      '[$map(result.numbers, function($n, $i) { {"target": {"holding": {"key": "issue.number", "value": $string($n)}}, "set": {"issue.state": result.states[$i]}} })]',
  },
},
actions: {
  create: {
    name: { en: "Create an issue" },
    endpoint: "create-issue", // returns number: int, url: string
    on: ["task"],
    write: '{"set": {"issue.number": result.number, "issue.link": {"url": result.url, "text": "#" & result.number}}}',
  },
  link: {
    name: { en: "Link an issue" },
    endpoint: "link-issue", // takes number: int; returns number: int, url: string, state: string
    params: ["number"],
    on: ["task"],
    write: '{"upsert": {"issues.linked": [{"ref": $string(result.number), "url": result.url, "state": {"status": result.state}}]}}',
  },
  unlink: { name: { en: "Unlink" }, on: ["task"], write: '{"remove": {"issues.linked": [element]}}' }, // a list field's element action
},

Wrap a list a write answers in [ ]: a JSONata path matching one item answers it alone, and a run refuses a lone change where a list belongs. - One plug-in is one kind. A declarative plug-in is a manifest Initiative runs, with no plug-in code: it has no handlers, hooks or pages. A container plug-in ships code, which Initiative calls, and uses none of the declarative terms. Any plug-in may keep values on items in Initiative: a container writes them with its installation token, and for a declarative plug-in Initiative writes them from the plug-in's expressions. validateManifest and build refuse a mix.

runEndpoint, runAfterConnect, runHealth, runAction and runSchedule render each request as Initiative sends it, less the credential, answer it from the recorded responses in order, and return the requests beside the result or the code the run answered. runEndpoint takes each connection's fields by id in connections, and the actor the call is made as, by default the endpoint's first: a request naming a connection per actor carries that actor's. It does not refuse a call the way Initiative would for who is making it. runAction takes the item, what the install held on it, the params the reader answered, the element it was run from and its endpoint's actor, and answers the endpoint's result and the change; runSchedule takes since, makes its read as the installation, and answers the endpoint's result and the writes; runWebhook answers a delivery's event, writes and status. Every runner but runExchangeBody takes the install's settings and aliases. A run fails when a request has no recorded answer left, when an answer is left over, when the map's answer does not fit the declared returns, or when a write answers what is not a change: one that changes a key twice, gives a list field anything but a list of elements, or upserts or removes elements of a field that is not a list.