Create an object
One script reply has been approved by the moderators Verified

Creates a new custom object in your workspace.

Required scopes: object_configuration:read-write.

Created by hugo697 51 days ago Picked 1 time
Submitted by hugo697 Bun
Verified 51 days ago
1
//native
2
type Attio = {
3
  token: string;
4
};
5
/**
6
 * Create an object
7
 * Creates a new custom object in your workspace.
8

9
Required scopes: `object_configuration:read-write`.
10
 */
11
export async function main(
12
  auth: Attio,
13
  body: {
14
    data: { api_slug: string; singular_noun: string; plural_noun: string };
15
  },
16
) {
17
  const url = new URL(`https://api.attio.com/v2/objects`);
18

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