Edits history of script submission #14059 for ' Create an entry (add record to list) (attio)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Attio = {
      token: string;
    };
    /**
     * Create an entry (add record to list)
     * Adds a record to a list as a new list entry. This endpoint will throw on conflicts of unique attributes. Multiple list entries are allowed for the same parent record
    
    Required scopes: `list_entry:read-write`, `list_configuration:read`.
     */
    export async function main(
      auth: Attio,
      list: string,
      body: {
        data: { parent_record_id: string; parent_object: string; entry_values: {} };
      },
    ) {
      const url = new URL(`https://api.attio.com/v2/lists/${list}/entries`);
    
      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