Edits history of script submission #11530 for ' Create Webhook (bitly)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Bitly = {
      token: string;
    };
    /**
     * Create Webhook
     * Creates a webhook.
     */
    export async function main(
      auth: Bitly,
      body: {
        is_active?: false | true;
        organization_guid: string;
        group_guid?: string;
        name: string;
        event: string;
        url: string;
        oauth_url?: string;
        client_id?: string;
        client_secret?: string;
        fetch_tags?: false | true;
      },
    ) {
      const url = new URL(`https://api-ssl.bitly.com/v4/webhooks`);
    
      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