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

Add a new status to a status attribute on either 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 status
7
 * Add a new status to a status attribute on either an object or a list.
8

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

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