//native
type Bitly = {
token: string;
};
/**
* Retrieve a QR Code image
* Get the image of a given QR Code.
*/
export async function main(
auth: Bitly,
qrcode_id: string,
format: "svg" | "png" | undefined,
Accept: string,
) {
const url = new URL(
`https://api-ssl.bitly.com/v4/qr-codes/${qrcode_id}/image`,
);
for (const [k, v] of [["format", format]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Accept: Accept,
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago