0

Update a QR Code

by
Published Apr 8, 2025

Updates the QR code with a matching id and returns it.

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 QR Code
7
 * Updates the QR code with a matching id and returns it.
8
 */
9
export async function main(
10
  auth: Bitly,
11
  qrcode_id: string,
12
  body: {
13
    title?: string;
14
    render_customizations?: {
15
      background_color?: string;
16
      dot_pattern_color?: string;
17
      dot_pattern_type?:
18
        | "standard"
19
        | "circle"
20
        | "block"
21
        | "blob"
22
        | "rounded"
23
        | "vertical"
24
        | "horizontal"
25
        | "triangle"
26
        | "heart"
27
        | "star"
28
        | "diamond";
29
      corners?: {
30
        corner_1?: {
31
          inner_color?: string;
32
          outer_color?: string;
33
          shape?:
34
            | "standard"
35
            | "rounded"
36
            | "slightly_round"
37
            | "extra_round"
38
            | "leaf"
39
            | "leaf_inner"
40
            | "leaf_outer"
41
            | "target"
42
            | "concave";
43
        };
44
        corner_2?: {
45
          inner_color?: string;
46
          outer_color?: string;
47
          shape?:
48
            | "standard"
49
            | "rounded"
50
            | "slightly_round"
51
            | "extra_round"
52
            | "leaf"
53
            | "leaf_inner"
54
            | "leaf_outer"
55
            | "target"
56
            | "concave";
57
        };
58
        corner_3?: {
59
          inner_color?: string;
60
          outer_color?: string;
61
          shape?:
62
            | "standard"
63
            | "rounded"
64
            | "slightly_round"
65
            | "extra_round"
66
            | "leaf"
67
            | "leaf_inner"
68
            | "leaf_outer"
69
            | "target"
70
            | "concave";
71
        };
72
      };
73
      gradient?: {
74
        style?: "no_gradient" | "linear" | "radial";
75
        angle?: number;
76
        colors?: { color?: string; offset?: number }[];
77
        exclude_corners?: false | true;
78
      };
79
      background_gradient?: {
80
        style?: "no_gradient" | "linear" | "radial";
81
        angle?: number;
82
        colors?: { color?: string; offset?: number }[];
83
        exclude_corners?: false | true;
84
      };
85
      logo?: { image_guid?: string };
86
      frame?: {
87
        id:
88
          | "none"
89
          | "border_only"
90
          | "text_bottom"
91
          | "tooltip_bottom"
92
          | "arrow"
93
          | "text_top"
94
          | "text_bottom_in_frame"
95
          | "script"
96
          | "text_top_and_bottom"
97
          | "url"
98
          | "instagram";
99
        colors?: { primary?: string; secondary?: string; background?: string };
100
        text?: {
101
          primary?: { content: string; color?: string };
102
          secondary?: { content: string; color?: string };
103
        };
104
      };
105
      text?: {
106
        center?: { content: string; color?: string };
107
        top?: { content: string; color?: string };
108
        bottom?: { content: string; color?: string };
109
      };
110
      branding?: { bitly_brand?: false | true };
111
      spec_settings?: { error_correction?: number };
112
    };
113
    archived?: false | true;
114
  },
115
) {
116
  const url = new URL(`https://api-ssl.bitly.com/v4/qr-codes/${qrcode_id}`);
117

118
  const response = await fetch(url, {
119
    method: "PATCH",
120
    headers: {
121
      "Content-Type": "application/json",
122
      Authorization: "Bearer " + auth.token,
123
    },
124
    body: JSON.stringify(body),
125
  });
126
  if (!response.ok) {
127
    const text = await response.text();
128
    throw new Error(`${response.status} ${text}`);
129
  }
130
  return await response.json();
131
}
132