0

Create a SAML Connection

by
Published Apr 8, 2025

Create a new SAML Connection.

Script clerk Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Clerk = {
3
  apiKey: string;
4
};
5
/**
6
 * Create a SAML Connection
7
 * Create a new SAML Connection.
8
 */
9
export async function main(
10
  auth: Clerk,
11
  body: {
12
    name: string;
13
    domain: string;
14
    provider: "saml_custom" | "saml_okta" | "saml_google" | "saml_microsoft";
15
    idp_entity_id?: string;
16
    idp_sso_url?: string;
17
    idp_certificate?: string;
18
    idp_metadata_url?: string;
19
    idp_metadata?: string;
20
    organization_id?: string;
21
    attribute_mapping?: {
22
      user_id?: string;
23
      email_address?: string;
24
      first_name?: string;
25
      last_name?: string;
26
    };
27
  },
28
) {
29
  const url = new URL(`https://api.clerk.com/v1/saml_connections`);
30

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