Edits history of script submission #15787 for ' Get the notifications that belong to the current user (discourse)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Discourse = {
      apiKey: string;
      defaultHost: string;
      apiUsername: string;
    };
    /**
     * Get the notifications that belong to the current user
     *
     */
    export async function main(auth: Discourse) {
      const url = new URL(`https://${auth.defaultHost}/notifications.json`);
    
      const response = await fetch(url, {
        method: "GET",
        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