0

Update a Channel

by
Published Apr 8, 2025

Updates an existing channel.

Script bitly Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Bitly = {
3
  token: string;
4
};
5
/**
6
 * Update a Channel
7
 * Updates an existing channel.
8
 */
9
export async function main(
10
  auth: Bitly,
11
  channel_guid: string,
12
  body: {
13
    name?: string;
14
    guid?: string;
15
    created?: string;
16
    modified?: string;
17
    group_guid?: string;
18
  } & { bitlinks?: { campaign_guid?: string; bitlink_id?: string }[] },
19
) {
20
  const url = new URL(`https://api-ssl.bitly.com/v4/channels/${channel_guid}`);
21

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