//native
type Klaviyo = {
apiKey: string;
};
/**
* Get Accounts
* 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`
*/
export async function main(
auth: Klaviyo,
fields_account_: string | undefined,
revision: string,
) {
const url = new URL(`https://a.klaviyo.com/api/accounts`);
for (const [k, v] of [["fields[account]", fields_account_]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
revision: revision,
"Accept": "application/vnd.api+json",
Authorization: "Klaviyo-API-Key " + auth.apiKey,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago