//native
type Codat = {
encodedKey: string
}
/**
* Get company access token
* Use the _Get company access token_ endpoint to return an access token for the specified company ID. The token is valid for one day.
The token is required by Codat's embeddable UIs (such as [Connections SDK](https://docs.codat.io/auth-flow/optimize/connection-management) and [Link SDK](https://docs.codat.io/auth-flow/authorize-embedded-link)) to verify the identity of the user and improve the reliability of data provided by them.
*/
export async function main(auth: Codat, companyId: string) {
const url = new URL(`https://api.codat.io/companies/${companyId}/accessToken`)
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: `Basic ${auth.encodedKey}`
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 235 days ago