When someone leaves, suspend their badge via api.badges.example.com and note it on the ticket.

It can call only api.badges.example.com, the one host in its domains. Add the API key and I'll test it.

Configured Badge deactivation

The test passed on test.user@example.com: their badge is suspended, and IT-4127 has the note.

index.ts
1// The one host this tool may call, for reads and writes
2export const domains = {
3"api.badges.example.com": "read_write",
4};
5
6export const input = z.object({
7email: z.string().email().describe("Who is leaving"),
8ticket_id: z.string().optional().describe("Their ticket"),
9});
10type Input = z.infer<typeof input>;
11
12const API = "https://api.badges.example.com/v2";
13
14export default async function run({ email, ticket_id }: Input) {
15const token = env.BADGE_API_KEY;
16
17// **Find the cardholder**
18const found = await http.get(`${API}/cardholders`, {
19query: { email },
20auth: { type: "bearer", token },
21});
22const holder =
23found.body.data[0] ?? fail(`No cardholder for ${email}.`);
24
25// **Suspend their badge**
26await http.post(`${API}/cardholders/${holder.id}/suspend`, {
27json: { reason: "Offboarded" },
28auth: { type: "bearer", token },
29});
30
31// **Note it on the ticket**
32await risotto.add_ticket_comment({
33ticket_id,
34comment: `Badge ${holder.badge} suspended for ${email}.`,
35});
36
37return `Suspended badge ${holder.badge} for ${email}.`;
38}
Flow

Find the cardholder

Suspend their badge

Note it on the ticket

Return

return

Find the cardholder

running

Suspend their badge

Note it on the ticket

Return

return

Find the cardholder

384 ms

Suspend their badge

running

Note it on the ticket

Return

return

Find the cardholder

384 ms

Suspend their badge

1.2 s

Note it on the ticket

running

Return

return

Find the cardholder

384 ms

Suspend their badge

1.2 s

Note it on the ticket

212 ms

Return

return