0

Update Campaign

by
Published Apr 8, 2025

Updates a campaign's details.

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 Campaign
7
 * Updates a campaign's details.
8
 */
9
export async function main(
10
  auth: Bitly,
11
  campaign_guid: string,
12
  body: {
13
    group_guid?: string;
14
    name?: string;
15
    description?: string;
16
    channel_guids?: string[];
17
  },
18
) {
19
  const url = new URL(
20
    `https://api-ssl.bitly.com/v4/campaigns/${campaign_guid}`,
21
  );
22

23
  const response = await fetch(url, {
24
    method: "PATCH",
25
    headers: {
26
      "Content-Type": "application/json",
27
      Authorization: "Bearer " + auth.token,
28
    },
29
    body: JSON.stringify(body),
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