Edits history of script submission #11527 for ' Bulk update bitlinks (bitly)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Bitly = {
      token: string;
    };
    /**
     * Bulk update bitlinks
     * Bulk update can add or remove tags or archive up to 100 links at a time; The response includes a list of bitlink ids that were updated.
     */
    export async function main(
      auth: Bitly,
      group_guid: string,
      body: {
        action: "archive" | "edit_tags";
        archive?: false | true;
        add_tags?: string[];
        remove_tags?: string[];
        links?: string[];
      },
    ) {
      const url = new URL(
        `https://api-ssl.bitly.com/v4/groups/${group_guid}/bitlinks`,
      );
    
      const response = await fetch(url, {
        method: "PATCH",
        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