0

Query Form Values

by
Published Apr 8, 2025

Returns the requested form analytics values 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 Values
7
 * Returns the requested form analytics values 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-values-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
        group_by?: "form_id" | "form_version_id"[];
50
        filter?: string;
51
      };
52
    };
53
  },
54
) {
55
  const url = new URL(`https://a.klaviyo.com/api/form-values-reports`);
56

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