0

Query Form Series

by
Published Apr 8, 2025

Returns the requested form analytics series data.*Rate limits*:Burst: `1/s`Steady: `2/m`Daily: `225/d` **Scopes:** `forms: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
 * Query Form Series
7
 * Returns the requested form analytics series data.*Rate limits*:Burst: `1/s`Steady: `2/m`Daily: `225/d`
8

9
 */
10
export async function main(
11
  auth: Klaviyo,
12
  revision: string,
13
  body: {
14
    data: {
15
      type: "form-series-report";
16
      attributes: {
17
        statistics:
18
          | "closed_form"
19
          | "closed_form_uniques"
20
          | "qualified_form"
21
          | "qualified_form_uniques"
22
          | "submit_rate"
23
          | "submits"
24
          | "submitted_form_step"
25
          | "submitted_form_step_uniques"
26
          | "viewed_form"
27
          | "viewed_form_step"
28
          | "viewed_form_step_uniques"
29
          | "viewed_form_uniques"[];
30
        timeframe:
31
          | {
32
              key:
33
                | "last_12_months"
34
                | "last_30_days"
35
                | "last_365_days"
36
                | "last_3_months"
37
                | "last_7_days"
38
                | "last_90_days"
39
                | "last_month"
40
                | "last_week"
41
                | "last_year"
42
                | "this_month"
43
                | "this_week"
44
                | "this_year"
45
                | "today"
46
                | "yesterday";
47
            }
48
          | { start: string; end: string };
49
        interval: "daily" | "hourly" | "monthly" | "weekly";
50
        group_by?: "form_id" | "form_version_id"[];
51
        filter?: string;
52
      };
53
    };
54
  },
55
) {
56
  const url = new URL(`https://a.klaviyo.com/api/form-series-reports`);
57

58
  const response = await fetch(url, {
59
    method: "POST",
60
    headers: {
61
      revision: revision,
62
      "Accept": "application/vnd.api+json",
63
      "Content-Type": "application/vnd.api+json",
64
      Authorization: "Klaviyo-API-Key " + auth.apiKey,
65
    },
66
    body: JSON.stringify(body),
67
  });
68
  if (!response.ok) {
69
    const text = await response.text();
70
    throw new Error(`${response.status} ${text}`);
71
  }
72
  return await response.json();
73
}
74