0

Refresh Campaign Recipient Estimation

by
Published Apr 8, 2025

Trigger an asynchronous job to update the estimated number of recipients for the given campaign ID. Use the `Get Campaign Recipient Estimation Job` endpoint to retrieve the status of this estimation job. Use the `Get Campaign Recipient Estimation` endpoint to retrieve the estimated recipient count for a given campaign.*Rate limits*:Burst: `10/s`Steady: `150/m` **Scopes:** `campaigns:write`

Script klaviyo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Klaviyo = {
3
  apiKey: string;
4
};
5
/**
6
 * Refresh Campaign Recipient Estimation
7
 * Trigger an asynchronous job to update the estimated number of recipients
8
for the given campaign ID. Use the `Get Campaign Recipient Estimation
9
Job` endpoint to retrieve the status of this estimation job. Use the
10
`Get Campaign Recipient Estimation` endpoint to retrieve the estimated
11
recipient count for a given campaign.*Rate limits*:Burst: `10/s`Steady: `150/m`
12

13
 */
14
export async function main(
15
  auth: Klaviyo,
16
  revision: string,
17
  body: { data: { type: "campaign-recipient-estimation-job"; id: string } },
18
) {
19
  const url = new URL(
20
    `https://a.klaviyo.com/api/campaign-recipient-estimation-jobs`,
21
  );
22

23
  const response = await fetch(url, {
24
    method: "POST",
25
    headers: {
26
      revision: revision,
27
      "Accept": "application/vnd.api+json",
28
      "Content-Type": "application/vnd.api+json",
29
      Authorization: "Klaviyo-API-Key " + auth.apiKey,
30
    },
31
    body: JSON.stringify(body),
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39