Edits history of script submission #12117 for ' Add a comment to a file (figma)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Figma = {
      token: string;
    };
    /**
     * Add a comment to a file
     * Posts a new comment on the file.
     */
    export async function main(
      auth: Figma,
      file_key: string,
      body: {
        message: string;
        comment_id?: string;
        client_meta?:
          | { x: number; y: number }
          | { node_id: string; node_offset: { x: number; y: number } }
          | {
              x: number;
              y: number;
              region_height: number;
              region_width: number;
              comment_pin_corner?:
                | "top-left"
                | "top-right"
                | "bottom-left"
                | "bottom-right";
            }
          | {
              node_id: string;
              node_offset: { x: number; y: number };
              region_height: number;
              region_width: number;
              comment_pin_corner?:
                | "top-left"
                | "top-right"
                | "bottom-left"
                | "bottom-right";
            };
      },
    ) {
      const url = new URL(`https://api.figma.com/v1/files/${file_key}/comments`);
    
      const response = await fetch(url, {
        method: "POST",
        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 428 days ago