0

Generate SSO token to access sub-account

by
Published Apr 8, 2025

This endpoint generates an sso token to authenticate and access a sub-account of the master using the account endpoint https://account-app.brevo.com/account/login/sub-account/sso/[token], where [token] will be replaced by the actual token.

Script brevo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Brevo = {
3
  apiKey: string;
4
};
5
/**
6
 * Generate SSO token to access sub-account
7
 * This endpoint generates an sso token to authenticate and access a sub-account of the master using the account endpoint https://account-app.brevo.com/account/login/sub-account/sso/[token], where [token] will be replaced by the actual token.
8
 */
9
export async function main(
10
  auth: Brevo,
11
  body: {
12
    id: number;
13
    email?: string;
14
    target?:
15
      | "automation"
16
      | "email_campaign"
17
      | "contacts"
18
      | "landing_pages"
19
      | "email_transactional"
20
      | "senders"
21
      | "sms_campaign"
22
      | "sms_transactional";
23
    url?: string;
24
  },
25
) {
26
  const url = new URL(`https://api.brevo.com/v3/corporate/subAccount/ssoToken`);
27

28
  const response = await fetch(url, {
29
    method: "POST",
30
    headers: {
31
      "Content-Type": "application/json",
32
      "api-key": auth.apiKey,
33
    },
34
    body: JSON.stringify(body),
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42