//native
type Neondb = {
apiKey: string
}
/**
* Create organization invitations
* Creates invitations for a specific organization.
If the invited user has an existing account, they automatically join as a member.
If they don't yet have an account, they are invited to create one, after which they become a member.
Each invited user receives an email notification.
*/
export async function main(
auth: Neondb,
org_id: string,
body: { invitations: { email: string; role: 'admin' | 'member' }[] }
) {
const url = new URL(`https://console.neon.tech/api/v2/organizations/${org_id}/invitations`)
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