//native
type Ably = {
accessToken: string;
};
/**
* Creates a key
* Creates an API key for the application specified.
*/
export async function main(
auth: Ably,
app_id: string,
body: { name: string; capability: {} },
) {
const url = new URL(`https://control.ably.net/v1/apps/${app_id}/keys`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.accessToken,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 185 days ago