Edits history of script submission #15825 for ' Update the status of a topic (discourse)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Discourse = {
      apiKey: string;
      defaultHost: string;
      apiUsername: string;
    };
    /**
     * Update the status of a topic
     *
     */
    export async function main(
      auth: Discourse,
      id: string,
      Api_Key: string,
      Api_Username: string,
      body: {
        status: "closed" | "pinned" | "pinned_globally" | "archived" | "visible";
        enabled: "true" | "false";
        until?: string;
      },
    ) {
      const url = new URL(`https://${auth.defaultHost}/t/${id}/status.json`);
    
      const response = await fetch(url, {
        method: "PUT",
        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