Edits history of script submission #14558 for ' Update task (box)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Box = {
      token: string;
    };
    /**
     * Update task
     * Updates a task. This can be used to update a task's configuration, or to
    update its completion state.
     */
    export async function main(
      auth: Box,
      task_id: string,
      body: {
        action?: "review" | "complete";
        message?: string;
        due_at?: string;
        completion_rule?: "all_assignees" | "any_assignee";
      },
    ) {
      const url = new URL(`https://api.box.com/2.0/tasks/${task_id}`);
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + 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