0

Retrieve Bitlinks by Group

by
Published Apr 8, 2025

Returns a paginated collection of Bitlinks for a group. The list of custom bitlinks has newest entries first.

Script bitly Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Bitly = {
3
  token: string;
4
};
5
/**
6
 * Retrieve Bitlinks by Group
7
 * Returns a paginated collection of Bitlinks for a group. The list of custom bitlinks has newest entries first.
8
 */
9
export async function main(
10
  auth: Bitly,
11
  group_guid: string,
12
  size: string | undefined,
13
  search_after: string | undefined,
14
  query: string | undefined,
15
  created_before: string | undefined,
16
  created_after: string | undefined,
17
  archived: "on" | "off" | "both" | undefined,
18
  deeplinks: "on" | "off" | "both" | undefined,
19
  domain_deeplinks: "on" | "off" | "both" | undefined,
20
  campaign_guid: string | undefined,
21
  channel_guid: string | undefined,
22
  custom_bitlink: "on" | "off" | "both" | undefined,
23
  has_qr_codes: "on" | "off" | "both" | undefined,
24
  tags: string | undefined,
25
  launchpad_ids: string | undefined,
26
  encoding_login: string | undefined,
27
) {
28
  const url = new URL(
29
    `https://api-ssl.bitly.com/v4/groups/${group_guid}/bitlinks`,
30
  );
31
  for (const [k, v] of [
32
    ["size", size],
33
    ["search_after", search_after],
34
    ["query", query],
35
    ["created_before", created_before],
36
    ["created_after", created_after],
37
    ["archived", archived],
38
    ["deeplinks", deeplinks],
39
    ["domain_deeplinks", domain_deeplinks],
40
    ["campaign_guid", campaign_guid],
41
    ["channel_guid", channel_guid],
42
    ["custom_bitlink", custom_bitlink],
43
    ["has_qr_codes", has_qr_codes],
44
    ["tags", tags],
45
    ["launchpad_ids", launchpad_ids],
46
    ["encoding_login", encoding_login],
47
  ]) {
48
    if (v !== undefined && v !== "" && k !== undefined) {
49
      url.searchParams.append(k, v);
50
    }
51
  }
52
  const response = await fetch(url, {
53
    method: "GET",
54
    headers: {
55
      Authorization: "Bearer " + auth.token,
56
    },
57
    body: undefined,
58
  });
59
  if (!response.ok) {
60
    const text = await response.text();
61
    throw new Error(`${response.status} ${text}`);
62
  }
63
  return await response.json();
64
}
65