//native
type Neondb = {
apiKey: string
}
/**
* Create an organization API key
* Creates an API key for the specified organization.
The `key_name` is a user-specified name for the key.
This method returns an `id` and `key`. The `key` is a randomly generated, 64-bit token required to access the Neon API.
API keys can also be managed in the Neon Console.
See [Manage API keys](https://neon.tech/docs/manage/api-keys/).
*/
export async function main(
auth: Neondb,
org_id: string,
body: { key_name: string } & { project_id?: string }
) {
const url = new URL(`https://console.neon.tech/api/v2/organizations/${org_id}/api_keys`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.apiKey
},
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 428 days ago