Edits history of script submission #11568 for ' Retrieve Bitlinks by Group (bitly)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Bitly = {
      token: string;
    };
    /**
     * Retrieve Bitlinks by Group
     * Returns a paginated collection of Bitlinks for a group. The list of custom bitlinks has newest entries first.
     */
    export async function main(
      auth: Bitly,
      group_guid: string,
      size: string | undefined,
      search_after: string | undefined,
      query: string | undefined,
      created_before: string | undefined,
      created_after: string | undefined,
      archived: "on" | "off" | "both" | undefined,
      deeplinks: "on" | "off" | "both" | undefined,
      domain_deeplinks: "on" | "off" | "both" | undefined,
      campaign_guid: string | undefined,
      channel_guid: string | undefined,
      custom_bitlink: "on" | "off" | "both" | undefined,
      has_qr_codes: "on" | "off" | "both" | undefined,
      tags: string | undefined,
      launchpad_ids: string | undefined,
      encoding_login: string | undefined,
    ) {
      const url = new URL(
        `https://api-ssl.bitly.com/v4/groups/${group_guid}/bitlinks`,
      );
      for (const [k, v] of [
        ["size", size],
        ["search_after", search_after],
        ["query", query],
        ["created_before", created_before],
        ["created_after", created_after],
        ["archived", archived],
        ["deeplinks", deeplinks],
        ["domain_deeplinks", domain_deeplinks],
        ["campaign_guid", campaign_guid],
        ["channel_guid", channel_guid],
        ["custom_bitlink", custom_bitlink],
        ["has_qr_codes", has_qr_codes],
        ["tags", tags],
        ["launchpad_ids", launchpad_ids],
        ["encoding_login", encoding_login],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          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