0

Add Connection from Source to Warehouse

by
Published Oct 17, 2025

Connects a Source to a Warehouse. • When called, this endpoint may generate the `Storage Destination Modified` 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
 * Add Connection from Source to Warehouse
8
 * Connects a Source to a Warehouse.
9

10

11

12
• When called, this endpoint may generate the `Storage Destination Modified` event in the audit trail.
13
      
14
 */
15
export async function main(
16
  auth: Segment,
17
  warehouseId: string,
18
  sourceId: string,
19
) {
20
  const url = new URL(
21
    `${auth.baseUrl}/warehouses/${warehouseId}/connected-sources/${sourceId}`,
22
  );
23

24
  const response = await fetch(url, {
25
    method: "POST",
26
    headers: {
27
      Authorization: "Bearer " + auth.token,
28
    },
29
    body: undefined,
30
  });
31
  if (!response.ok) {
32
    const text = await response.text();
33
    throw new Error(`${response.status} ${text}`);
34
  }
35
  return await response.json();
36
}
37