0

Get bulk operation batches

by
Published Oct 17, 2025

Retrieves detailed batch information for a specific bulk operation, including individual object IDs created or processed during the operation.

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Get bulk operation batches
7
 * Retrieves detailed batch information for a specific bulk operation, including individual object IDs created or processed during the operation.
8
 */
9
export async function main(
10
  auth: Kustomer,
11
  id: string,
12
  page: string | undefined,
13
  sort: "createdAt" | "-createdAt" | undefined,
14
  status: "queued" | "scheduled" | "complete" | undefined,
15
  completed: "true" | "false" | undefined,
16
  limit: string | undefined,
17
) {
18
  const url = new URL(`https://api.kustomerapp.com/v1/bulk/${id}/batches`);
19
  for (const [k, v] of [
20
    ["page", page],
21
    ["sort", sort],
22
    ["status", status],
23
    ["completed", completed],
24
    ["limit", limit],
25
  ]) {
26
    if (v !== undefined && v !== "" && k !== undefined) {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "GET",
32
    headers: {
33
      Authorization: "Bearer " + auth.apiKey,
34
    },
35
    body: undefined,
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43