0

Bulk update bitlinks

by
Published Apr 8, 2025

Bulk update can add or remove tags or archive up to 100 links at a time; The response includes a list of bitlink ids that were updated.

Script bitly Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Bitly = {
3
  token: string;
4
};
5
/**
6
 * Bulk update bitlinks
7
 * Bulk update can add or remove tags or archive up to 100 links at a time; The response includes a list of bitlink ids that were updated.
8
 */
9
export async function main(
10
  auth: Bitly,
11
  group_guid: string,
12
  body: {
13
    action: "archive" | "edit_tags";
14
    archive?: false | true;
15
    add_tags?: string[];
16
    remove_tags?: string[];
17
    links?: string[];
18
  },
19
) {
20
  const url = new URL(
21
    `https://api-ssl.bitly.com/v4/groups/${group_guid}/bitlinks`,
22
  );
23

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