Creates an app
One script reply has been approved by the moderators Verified

Creates an application with the specified properties.

Created by hugo697 138 days ago Picked 6 times
Submitted by hugo697 Bun
Verified 138 days ago
1
//native
2
type Ably = {
3
  accessToken: string;
4
};
5
/**
6
 * Creates an app
7
 * Creates an application with the specified properties.
8
 */
9
export async function main(
10
  auth: Ably,
11
  account_id: string,
12
  body: {
13
    name: string;
14
    status?: string;
15
    tlsOnly?: false | true;
16
    fcmKey?: string;
17
    fcmServiceAccount?: string;
18
    fcmProjectId?: string;
19
    apnsCertificate?: string;
20
    apnsPrivateKey?: string;
21
    apnsUseSandboxEndpoint?: false | true;
22
  },
23
) {
24
  const url = new URL(
25
    `https://control.ably.net/v1/accounts/${account_id}/apps`,
26
  );
27

28
  const response = await fetch(url, {
29
    method: "POST",
30
    headers: {
31
      "Content-Type": "application/json",
32
      Authorization: "Bearer " + auth.accessToken,
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