//native
type Codat = {
encodedKey: string
}
/**
* Create API key
* Use the *Create API keys* endpoint to generate a new API key for your client.
*/
export async function main(auth: Codat, body: { name?: string }) {
const url = new URL(`https://api.codat.io/apiKeys`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Basic ${auth.encodedKey}`
},
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 235 days ago