0

Get Accounts

by
Published Apr 8, 2025

Retrieve the account(s) associated with a given private API key. This will return 1 account object within the array. You can use this to retrieve account-specific data (contact information, timezone, currency, Public API key, etc.) or test if a Private API Key belongs to the correct account prior to performing subsequent actions with the API.*Rate limits*:Burst: `1/s`Steady: `15/m` **Scopes:** `accounts: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 Accounts
7
 * Retrieve the account(s) associated with a given private API key. This will return 1 account object within the array.
8

9
You can use this to retrieve account-specific data (contact information, timezone, currency, Public API key, etc.) or test if a Private API Key belongs to the correct account prior to performing subsequent actions with the API.*Rate limits*:Burst: `1/s`Steady: `15/m`
10

11
 */
12
export async function main(
13
  auth: Klaviyo,
14
  fields_account_: string | undefined,
15
  revision: string,
16
) {
17
  const url = new URL(`https://a.klaviyo.com/api/accounts`);
18
  for (const [k, v] of [["fields[account]", fields_account_]]) {
19
    if (v !== undefined && v !== "" && k !== undefined) {
20
      url.searchParams.append(k, v);
21
    }
22
  }
23
  const response = await fetch(url, {
24
    method: "GET",
25
    headers: {
26
      revision: revision,
27
      "Accept": "application/vnd.api+json",
28
      Authorization: "Klaviyo-API-Key " + auth.apiKey,
29
    },
30
    body: undefined,
31
  });
32
  if (!response.ok) {
33
    const text = await response.text();
34
    throw new Error(`${response.status} ${text}`);
35
  }
36
  return await response.json();
37
}
38