0

Update a Bitlink

by
Published Apr 8, 2025

Updates fields in the specified link. To redirect the link (i.e. to update the Long URL), use PATCH /v4/custom_bitlinks/{custom_bitlink} (https://dev.bitly.com/api-reference/#updateCustomBitlink)

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 Bitlink
7
 * Updates fields in the specified link. To redirect the link (i.e. to update the Long URL), use PATCH /v4/custom_bitlinks/{custom_bitlink} (https://dev.bitly.com/api-reference/#updateCustomBitlink)
8
 */
9
export async function main(
10
  auth: Bitly,
11
  bitlink: string,
12
  body: {
13
    title?: string;
14
    archived?: false | true;
15
    tags?: string[];
16
    deeplinks?: {
17
      guid?: string;
18
      bitlink?: string;
19
      app_uri_path?: string;
20
      install_url?: string;
21
      app_guid?: string;
22
      os?: "ios" | "android";
23
      install_type?: "no_install" | "auto_install" | "promote_install";
24
      created?: string;
25
      modified?: string;
26
      brand_guid?: string;
27
    }[];
28
  },
29
) {
30
  const url = new URL(`https://api-ssl.bitly.com/v4/bitlinks/${bitlink}`);
31

32
  const response = await fetch(url, {
33
    method: "PATCH",
34
    headers: {
35
      "Content-Type": "application/json",
36
      Authorization: "Bearer " + auth.token,
37
    },
38
    body: JSON.stringify(body),
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.json();
45
}
46