Edits history of script submission #11532 for ' Create a QR Code (bitly)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Bitly = {
      token: string;
    };
    /**
     * Create a QR Code
     * Create a new QR Code and return its metadata
     */
    export async function main(
      auth: Bitly,
      body: {
        title?: string;
        group_guid: string;
        render_customizations?: {
          background_color?: string;
          dot_pattern_color?: string;
          dot_pattern_type?:
            | "standard"
            | "circle"
            | "block"
            | "blob"
            | "rounded"
            | "vertical"
            | "horizontal"
            | "triangle"
            | "heart"
            | "star"
            | "diamond";
          corners?: {
            corner_1?: {
              inner_color?: string;
              outer_color?: string;
              shape?:
                | "standard"
                | "rounded"
                | "slightly_round"
                | "extra_round"
                | "leaf"
                | "leaf_inner"
                | "leaf_outer"
                | "target"
                | "concave";
            };
            corner_2?: {
              inner_color?: string;
              outer_color?: string;
              shape?:
                | "standard"
                | "rounded"
                | "slightly_round"
                | "extra_round"
                | "leaf"
                | "leaf_inner"
                | "leaf_outer"
                | "target"
                | "concave";
            };
            corner_3?: {
              inner_color?: string;
              outer_color?: string;
              shape?:
                | "standard"
                | "rounded"
                | "slightly_round"
                | "extra_round"
                | "leaf"
                | "leaf_inner"
                | "leaf_outer"
                | "target"
                | "concave";
            };
          };
          gradient?: {
            style?: "no_gradient" | "linear" | "radial";
            angle?: number;
            colors?: { color?: string; offset?: number }[];
            exclude_corners?: false | true;
          };
          background_gradient?: {
            style?: "no_gradient" | "linear" | "radial";
            angle?: number;
            colors?: { color?: string; offset?: number }[];
            exclude_corners?: false | true;
          };
          logo?: { image_guid?: string };
          frame?: {
            id:
              | "none"
              | "border_only"
              | "text_bottom"
              | "tooltip_bottom"
              | "arrow"
              | "text_top"
              | "text_bottom_in_frame"
              | "script"
              | "text_top_and_bottom"
              | "url"
              | "instagram";
            colors?: { primary?: string; secondary?: string; background?: string };
            text?: {
              primary?: { content: string; color?: string };
              secondary?: { content: string; color?: string };
            };
          };
          text?: {
            center?: { content: string; color?: string };
            top?: { content: string; color?: string };
            bottom?: { content: string; color?: string };
          };
          branding?: { bitly_brand?: false | true };
          spec_settings?: { error_correction?: number };
        };
        archived?: false | true;
        destination: { bitlink_id?: string; long_url?: string; site_id?: string };
        gs1?: { values?: { key?: string; value?: string }[] };
      },
    ) {
      const url = new URL(`https://api-ssl.bitly.com/v4/qr-codes`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 428 days ago