Edits history of script submission #14052 for ' Create a note (attio)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Attio = {
      token: string;
    };
    /**
     * Create a note
     * Creates a new note for a given record.
    
    At present, notes can only be created from plaintext without formatting.
    
    Required scopes: `note:read-write`, `object_configuration:read`, `record_permission:read`.
     */
    export async function main(
      auth: Attio,
      body: {
        data: {
          parent_object: string;
          parent_record_id: string;
          title: string;
          format: "plaintext";
          content: string;
          created_at?: string;
        };
      },
    ) {
      const url = new URL(`https://api.attio.com/v2/notes`);
    
      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 235 days ago