Send results to a destination
This guide sets up a destination, a place outside Kindgi that schedules
send their results to (runtime 0.7.0 or later), tests it, and shows what it
sent. A schedule names it in its sendResultsTo, as
Run on a schedule
shows.
Destinations are a tenant admin's: every call here but one answers
403 permission-denied to anyone else. The one is
destinations.list({ projectId }), which shows anyone who may run in that
project the destinations its schedules may use, without where they send. An
older runtime doesn't serve /v1/destinations.
The kinds
Section titled “The kinds”A destination's kind says where it sends:
email: some of the workspace's members, by email.peoplelists their user ids, 1 to 50. One that isn't a member of the workspace answers400 bad-input, naming it. Each one is checked again when a message goes: a person who has left the workspace, or can't read the run's project, is skipped (no-access).slack,teams,google-chatanddiscord: a channel's incoming webhook, by itsurlorurlRef.webhook: your own endpoint, by itsurlorurlRef, signed with the secret itssecretRefnames.
A deployment may not send every kind. A kind it can't send is refused with
400 bad-input, and details.setting names the setting it needs.
Make one
Section titled “Make one”Each destination needs a name, up to 100 characters, and its kind. This
code makes one for a Slack channel:
import { createClient } from '@kindgi/sdk/client';
const kindgi = createClient(); // KINDGI_API_URL, KINDGI_API_TOKEN
const alerts = await kindgi.destinations.create({ name: 'ops alerts', kind: 'slack', url: 'https://hooks.slack.com/services/<your-webhook-path>',});console.log(alerts.destinationId, alerts.host);from kindgi.client import Kindgi
kindgi = Kindgi() # KINDGI_API_URL, KINDGI_API_TOKEN
alerts = kindgi.destinations.create( name="ops alerts", kind="slack", url="https://hooks.slack.com/services/<your-webhook-path>",)print(alerts.destination_id, alerts.host)package com.acme.app;
import com.kindgi.client.Kindgi;import com.kindgi.client.models.CreateDestinationBody;import com.kindgi.client.models.Destination;import com.kindgi.client.models.DestinationKind;
public final class MakeDestination { public static void main(String[] args) { Kindgi kindgi = Kindgi.create(); // KINDGI_API_URL, KINDGI_API_TOKEN, or the running kindgi dev
Destination alerts = kindgi.destinations().create(CreateDestinationBody.builder() .name("ops alerts") .kind(DestinationKind.SLACK) .url("https://hooks.slack.com/services/<your-webhook-path>") .build()); System.out.println(alerts.destinationId() + " " + alerts.host()); }}package acme.app
import com.kindgi.client.Kindgiimport com.kindgi.client.models.{CreateDestinationBody, DestinationKind}
object MakeDestination { def main(args: Array[String]): Unit = { val kindgi = Kindgi.create() // KINDGI_API_URL, KINDGI_API_TOKEN, or the running kindgi dev
val alerts = kindgi.destinations().create(CreateDestinationBody.builder() .name("ops alerts") .kind(DestinationKind.SLACK) .url("https://hooks.slack.com/services/<your-webhook-path>") .build()) println(s"${alerts.destinationId} ${alerts.host}") }}POST /v1/destinations answers 201 with the destination. Its
destinationId is what a schedule's sendResultsTo names. An email
destination takes people in place of a URL, such as
{ name: 'order desk leads', kind: 'email', people: ['<user-id>'] }.
urlis an absolutehttpsURL, up to 2,048 characters, with no user name or password in it. A chat kind's must be on that service's own host, such ashooks.slack.comforslack, and the deployment may refuse private network addresses. Either answers400 destination-url-refused, withdetails.reason.projects, up to 100 project ids, limits which projects' schedules may use it. Left out, every project's may. A project that doesn't exist answers404 project-not-found.- A field that doesn't fit the kind, such as
peopleon aslackdestination, answers400 bad-inputnaming it. A field it doesn't know answers400 unknown-field. create,update,remove,sendTestandredelivertake an idempotency key:{ idempotencyKey }as the last argument in TypeScript,idempotency_key=in Python.
Its URL is write-only
Section titled “Its URL is write-only”A chat webhook's URL lets anyone who has it post to that channel, so it's a
credential. url goes in on create or update, and the runtime keeps it in
the tenant's secrets store, under a reserved kindgi. name that no caller
of /v1/secrets can read or write over. It never comes back: a destination
shows its host, and no delivery, log line or lastError holds the URL,
its path or its query.
If you keep your secrets elsewhere, store the URL first, as
Store a secret shows, and name it with
urlRef: { envName, name } in place of url (url_ref= in Python).
- The secret must exist, or
400 destination-secret-not-found. - It can't be a model provider's key (
400 provider-key-refused) or akindgi.name (400 reserved-name-prefix). - On a deployment that serves only its own environment, a reference under
another one answers
409 env-not-served.
Sign a webhook destination
Section titled “Sign a webhook destination”A webhook destination sends the same signed requests as a webhook
endpoint, in the Standard Webhooks format. Its secretRef names the
signing secret: whsec_ and the base64 of at least 24 random bytes, or
400 destination-secret-too-weak. The checks on urlRef above hold for it
too.
Get a webhook when a run finishes
makes and stores one, and Verify a webhook
checks it in your app.
import { createClient } from '@kindgi/sdk/client';
const kindgi = createClient(); // KINDGI_API_URL, KINDGI_API_TOKEN
await kindgi.destinations.create({ name: 'acme tickets', kind: 'webhook', url: 'https://tickets.acme.example/hooks/kindgi', secretRef: { envName: 'local', name: 'ACME_WEBHOOK_SECRET' },});from kindgi.client import Kindgi
kindgi = Kindgi() # KINDGI_API_URL, KINDGI_API_TOKEN
kindgi.destinations.create( name="acme tickets", kind="webhook", url="https://tickets.acme.example/hooks/kindgi", secret_ref={"envName": "local", "name": "ACME_WEBHOOK_SECRET"},)package com.acme.app;
import com.kindgi.client.Kindgi;import com.kindgi.client.models.CreateDestinationBody;import com.kindgi.client.models.DestinationKind;import com.kindgi.client.models.DestinationSecretRef;
public final class MakeWebhookDestination { public static void main(String[] args) { Kindgi kindgi = Kindgi.create(); // KINDGI_API_URL, KINDGI_API_TOKEN, or the running kindgi dev
kindgi.destinations().create(CreateDestinationBody.builder() .name("acme tickets") .kind(DestinationKind.WEBHOOK) .url("https://tickets.acme.example/hooks/kindgi") .secretRef(DestinationSecretRef.builder().envName("local").name("ACME_WEBHOOK_SECRET").build()) .build()); }}package acme.app
import com.kindgi.client.Kindgiimport com.kindgi.client.models.{CreateDestinationBody, DestinationKind, DestinationSecretRef}
object MakeWebhookDestination { def main(args: Array[String]): Unit = { val kindgi = Kindgi.create() // KINDGI_API_URL, KINDGI_API_TOKEN, or the running kindgi dev
kindgi.destinations().create(CreateDestinationBody.builder() .name("acme tickets") .kind(DestinationKind.WEBHOOK) .url("https://tickets.acme.example/hooks/kindgi") .secretRef(DestinationSecretRef.builder().envName("local").name("ACME_WEBHOOK_SECRET").build()) .build()) }}A message can arrive more than once. Its webhook-id header is the same
on every attempt, so your app can act on each one once. Chat kinds have no
such id, so a retry after a lost answer can post twice.
What a message carries
Section titled “What a message carries”content says what each message holds:
link, the default: the run's status and its console link.answer: the run's answer too, up to its first 1,000 characters. It needsprojects, so only the answers of the projects it names go there. Without them, it answers400 bad-input. Awebhookdestination never takes it: its receiver reads the run with its own key.
Change one
Section titled “Change one”update changes only the fields you give it. This code sends one project's
answers to the channel:
import { createClient } from '@kindgi/sdk/client';
const kindgi = createClient(); // KINDGI_API_URL, KINDGI_API_TOKEN
await kindgi.destinations.update('<destination-id>', { content: 'answer', projects: ['<project-id>'],});from kindgi.client import Kindgi
kindgi = Kindgi() # KINDGI_API_URL, KINDGI_API_TOKEN
kindgi.destinations.update( "<destination-id>", content="answer", projects=["<project-id>"],)package com.acme.app;
import com.kindgi.client.Kindgi;import com.kindgi.client.models.DestinationContent;import com.kindgi.client.models.UpdateDestinationBody;import java.util.List;import java.util.UUID;
public final class SendAnswers { public static void main(String[] args) { Kindgi kindgi = Kindgi.create(); // KINDGI_API_URL, KINDGI_API_TOKEN, or the running kindgi dev
kindgi.destinations().update(UUID.fromString("<destination-id>"), UpdateDestinationBody.builder() .content(DestinationContent.ANSWER) .projects(List.of(UUID.fromString("<project-id>"))) .build()); }}package acme.app
import com.kindgi.client.Kindgiimport com.kindgi.client.models.{DestinationContent, UpdateDestinationBody}import java.util.UUIDimport scala.jdk.CollectionConverters._
object SendAnswers { def main(args: Array[String]): Unit = { val kindgi = Kindgi.create() // KINDGI_API_URL, KINDGI_API_TOKEN, or the running kindgi dev
kindgi.destinations().update(UUID.fromString("<destination-id>"), UpdateDestinationBody.builder() .content(DestinationContent.ANSWER) .projects(List(UUID.fromString("<project-id>")).asJava) .build()) }}PATCH /v1/destinations/{destinationId} answers 200 with the destination.
- Fields left out are kept.
kindnever changes: make a destination of the other kind instead.- A new
urlreplaces the stored one, and aurlRefreplaces where it's kept. Leave both out to keep it. projects: null(projects=Nonein Python,.projects(null)in Java) lets every project's schedules use it again.- The destination as changed must still fit its kind:
content: 'answer'with noprojectsis refused, as on create.
Test it
Section titled “Test it”sendTest('<destination-id>') (send_test in Python),
POST /v1/destinations/{destinationId}/test, queues a destination.test
message to check it end to end. It answers 202 with that delivery: follow
it in the destination's deliveries, below.
A destination's status is active, or failing when its last delivery
got an answer a retry won't change, such as a removed webhook's 404 or
410. Its lastError says why. While it's failing, new messages for it are
kept but held pending. A test that reaches it makes it active again,
and its held messages still within their retry window go out, oldest
first.
See what it sent
Section titled “See what it sent”listDeliveries('<destination-id>') (list_deliveries in Python),
GET /v1/destinations/{destinationId}/deliveries, pages its messages,
newest first. status lists the ones in one status. Each has its event
(run.finished, approval.requested, destination.test or
rate-cap.summary), the scheduleId, runId or approvalId it's about,
its status and reason, its attempts, and the lastResponseStatus and
lastError of its last attempt. The statuses and reasons are a schedule's, as
Where its results went
lists them. A failed delivery never fails, pauses or slows the run or its
schedule.
redeliver('<destination-id>', '<delivery-id>'),
POST /v1/destinations/{destinationId}/deliveries/{deliveryId}/redeliver,
queues a delivery again now, whatever its status: its attempts start over,
and so does its retry window, about a day. On a failing destination it's
held, as new messages are, until a test reaches it. It's checked again as
when it was queued and as when it's sent, so one skipped as
not-for-this-project or no-access is skipped again for that reason. One
skipped for rate-cap goes out. It answers 202 with the delivery.
Remove one
Section titled “Remove one”remove('<destination-id>'), DELETE /v1/destinations/{destinationId},
answers 204. Its stored URL is revoked. Kindgi keeps its record, but it
can't be read again: get, update, its deliveries, sendTest,
redeliver and a second remove answer 404 destination-not-found. Schedules that still
name it send it nothing: each of their messages is recorded skipped, with
destination-removed.