//native
type Codat = {
encodedKey: string
}
/**
* Unlink connection
* This allows you to deauthorize a connection, without deleting it from Codat. This means you can still view any data that has previously been pulled into Codat, and also lets you re-authorize in future if your customer wishes to resume sharing their data.
*/
export async function main(
auth: Codat,
companyId: string,
connectionId: string,
body: { status?: 'PendingAuth' | 'Linked' | 'Unlinked' | 'Deauthorized' }
) {
const url = new URL(`https://api.codat.io/companies/${companyId}/connections/${connectionId}`)
const response = await fetch(url, {
method: 'PATCH',
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