//native
type Codat = {
encodedKey: string
}
/**
* End upload session
* Use the *End upload session* endpoint to finalize a bank statement upload session. Include a `status` in the request body to indicate if you want to cancel the processing of the dataset or trigger the ingestion and enrichment of the data.
A session is a one-time process that enables you to upload bank statements to Codat. It will time out after 90 minutes if no data is uploaded.
*/
export async function main(
auth: Codat,
companyId: string,
connectionId: string,
datasetId: string,
body: { status?: 'Cancel' | 'Process' }
) {
const url = new URL(
`https://api.codat.io/companies/${companyId}/connections/${connectionId}/bankStatements/upload/dataset/${datasetId}/endSession`
)
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.text()
}
Submitted by hugo697 235 days ago