Edits history of script submission #15750 for ' Create an invite (discourse)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Discourse = {
      apiKey: string;
      defaultHost: string;
      apiUsername: string;
    };
    /**
     * Create an invite
     *
     */
    export async function main(
      auth: Discourse,
      body: {
        email?: string;
        skip_email?: false | true;
        custom_message?: string;
        max_redemptions_allowed?: number;
        topic_id?: number;
        group_ids?: string;
        group_names?: string;
        expires_at?: string;
      },
    ) {
      const url = new URL(`https://${auth.defaultHost}/invites.json`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "API-KEY": auth.apiKey,
          "API-USERNAME": auth.apiUsername,
        },
        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 235 days ago