0

Get Campaign Recipient Estimation Job

by
Published Apr 8, 2025

Retrieve the status of a recipient estimation job triggered with the `Create Campaign Recipient Estimation Job` endpoint.*Rate limits*:Burst: `10/s`Steady: `150/m` **Scopes:** `campaigns:read`

Script klaviyo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Klaviyo = {
3
  apiKey: string;
4
};
5
/**
6
 * Get Campaign Recipient Estimation Job
7
 * Retrieve the status of a recipient estimation job triggered
8
with the `Create Campaign Recipient Estimation Job` endpoint.*Rate limits*:Burst: `10/s`Steady: `150/m`
9

10
 */
11
export async function main(
12
  auth: Klaviyo,
13
  id: string,
14
  fields_campaign_recipient_estimation_job_: string | undefined,
15
  revision: string,
16
) {
17
  const url = new URL(
18
    `https://a.klaviyo.com/api/campaign-recipient-estimation-jobs/${id}`,
19
  );
20
  for (const [k, v] of [
21
    [
22
      "fields[campaign-recipient-estimation-job]",
23
      fields_campaign_recipient_estimation_job_,
24
    ],
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
      revision: revision,
34
      "Accept": "application/vnd.api+json",
35
      Authorization: "Klaviyo-API-Key " + auth.apiKey,
36
    },
37
    body: undefined,
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45