0

Create Source

by
Published Oct 17, 2025

Creates a new Source. • When called, this endpoint may generate the `Source Created` event in the audit trail.

Script segment Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Segment = {
3
  token: string;
4
  baseUrl: string;
5
};
6
/**
7
 * Create Source
8
 * Creates a new Source.
9

10

11

12
• When called, this endpoint may generate the `Source Created` event in the audit trail.
13
      
14
 */
15
export async function main(
16
  auth: Segment,
17
  body: {
18
    slug: string;
19
    enabled: false | true;
20
    metadataId: string;
21
    settings?: {};
22
    disconnectAllWarehouses?: false | true;
23
  },
24
) {
25
  const url = new URL(`${auth.baseUrl}/sources`);
26

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