Edits history of script submission #11531 for ' Create a Bitlink (bitly)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Bitly = {
      token: string;
    };
    /**
     * Create a Bitlink
     * Converts a long url to a Bitlink and sets additional parameters. You may see errors returned from this endpoint - "BRANDED_LINK_MONTHLY_LIMIT_EXCEEDED" occurs if you have shortened more links than your account is configured for for the month, and "DNS_CONFIGURATION_ERROR" occurs if you are attempting to shorten links against a custom domain which doesn't have DNS properly configured.
     */
    export async function main(
      auth: Bitly,
      body: {
        long_url: string;
        domain?: string;
        group_guid?: string;
        title?: string;
        tags?: string[];
        deeplinks?: {
          app_id?: string;
          app_uri_path?: string;
          install_url?: string;
          install_type?: "no_install" | "auto_install" | "promote_install";
        }[];
      },
    ) {
      const url = new URL(`https://api-ssl.bitly.com/v4/bitlinks`);
    
      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