Create an entry (add record to list)
One script reply has been approved by the moderators Verified

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.

Created by hugo697 51 days ago
Submitted by hugo697 Bun
Verified 51 days ago
1
//native
2
type Attio = {
3
  token: string;
4
};
5
/**
6
 * Create an entry (add record to list)
7
 * 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
8

9
Required scopes: `list_entry:read-write`, `list_configuration:read`.
10
 */
11
export async function main(
12
  auth: Attio,
13
  list: string,
14
  body: {
15
    data: { parent_record_id: string; parent_object: string; entry_values: {} };
16
  },
17
) {
18
  const url = new URL(`https://api.attio.com/v2/lists/${list}/entries`);
19

20
  const response = await fetch(url, {
21
    method: "POST",
22
    headers: {
23
      "Content-Type": "application/json",
24
      Authorization: "Bearer " + auth.token,
25
    },
26
    body: JSON.stringify(body),
27
  });
28
  if (!response.ok) {
29
    const text = await response.text();
30
    throw new Error(`${response.status} ${text}`);
31
  }
32
  return await response.json();
33
}
34