Edits history of script submission #20480 for ' Edit a comment (smartsheet)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Smartsheet = {
      token: string;
      baseUrl: string;
    };
    /**
     * Edit a comment
     * Updates the text of a comment. NOTE: Only the user that created the comment is permitted to update it.
    
     */
    export async function main(
      auth: Smartsheet,
      sheetId: string,
      commentId: string,
      body: { text?: string },
    ) {
      const url = new URL(
        `${auth.baseUrl}/sheets/${sheetId}/comments/${commentId}`,
      );
    
      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