0

Update Source

by
Published Oct 17, 2025

Updates an existing Source. • When called, this endpoint may generate one or more of the following audit trail events:* Source Modified * Source Enabled * Source Settings Modified * Source Disabled Config API omitted fields: - `updateMask`

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
 * Update Source
8
 * Updates an existing Source.
9

10

11

12
• When called, this endpoint may generate one or more of the following audit trail events:* Source Modified
13
* Source Enabled
14
* Source Settings Modified
15
* Source Disabled
16

17
Config API omitted fields:
18
- `updateMask`
19

20
 */
21
export async function main(
22
  auth: Segment,
23
  sourceId: string,
24
  body: { name?: string; enabled?: false | true; slug?: string; settings?: {} },
25
) {
26
  const url = new URL(`${auth.baseUrl}/sources/${sourceId}`);
27

28
  const response = await fetch(url, {
29
    method: "PATCH",
30
    headers: {
31
      "Content-Type": "application/json",
32
      Authorization: "Bearer " + auth.token,
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