0

Update work item

by
Published Oct 17, 2025

Updates a work item based on its unique ID.

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Update work item
7
 * Updates a work item based on its unique ID.
8
 */
9
export async function main(
10
  auth: Kustomer,
11
  id: string,
12
  body: {
13
    queue?: {};
14
    routed?:
15
      | { to: string; at?: string }
16
      | { rejectedBy: string }
17
      | { timedout: false | true };
18
    accepted?: { at?: string; by: string; workSession?: string };
19
    status?: "assigned" | "wrap-up" | "completed";
20
    paused?: false | true;
21
    assignedTo?: string;
22
    rev: number;
23
    resource?: { rev?: number };
24
  },
25
) {
26
  const url = new URL(
27
    `https://api.kustomerapp.com/v1/routing/work-items/${id}`,
28
  );
29

30
  const response = await fetch(url, {
31
    method: "PUT",
32
    headers: {
33
      "Content-Type": "application/json",
34
      Authorization: "Bearer " + auth.apiKey,
35
    },
36
    body: JSON.stringify(body),
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44