Edits history of script submission #15742 for ' Activate a user (discourse)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Discourse = {
      apiKey: string;
      defaultHost: string;
      apiUsername: string;
    };
    /**
     * Activate a user
     *
     */
    export async function main(auth: Discourse, id: string) {
      const url = new URL(`https://${auth.defaultHost}/admin/users/${id}/activate.json`);
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "API-KEY": auth.apiKey,
          "API-USERNAME": auth.apiUsername,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago