Create title
One script reply has been approved by the moderators Verified

This endpoint creates a new title

Created by hugo697 170 days ago
Submitted by hugo697 Bun
Verified 170 days ago
1
//native
2
type Brex = {
3
  token: string;
4
};
5
/**
6
 * 
7
Create title
8

9
 * 
10
This endpoint creates a new title
11

12
 */
13
export async function main(
14
  auth: Brex,
15
  body: { name: string },
16
  Idempotency_Key?: string,
17
) {
18
  const url = new URL(`https://platform.brexapis.com/v2/titles`);
19

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