Edits history of script submission #14694 for ' Create a Channel on a Space, Folder, or List (clickup)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Clickup = {
      token: string;
    };
    /**
     * Create a Channel on a Space, Folder, or List
     * This endpoint creates a Channel and when a Channel already exists on the requested location, it returns it.
     */
    export async function main(
      auth: Clickup,
      workspace_id: string,
      body: {
        description?: string;
        topic?: string;
        user_ids?: string[];
        visibility?: "PUBLIC" | "PRIVATE";
        location: { id: string; type: "folder" | "list" | "space" };
      },
    ) {
      const url = new URL(
        `https://api.clickup.com/api/v3/workspaces/${workspace_id}/chat/channels/location`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: 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 235 days ago