Create a select option
One script reply has been approved by the moderators Verified

Adds a select option to a select attribute on an object or a list.

Required scopes: object_configuration:read-write.

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 a select option
7
 * Adds a select option to a select attribute on an object or a list.
8

9
Required scopes: `object_configuration:read-write`.
10
 */
11
export async function main(
12
  auth: Attio,
13
  target: "objects" | "lists",
14
  identifier: string,
15
  attribute: string,
16
  body: { data: { title: string } },
17
) {
18
  const url = new URL(
19
    `https://api.attio.com/v2/${target}/${identifier}/attributes/${attribute}/options`,
20
  );
21

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