0

End upload session

by
Published Oct 17, 2025

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.

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * End upload session
7
 * 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.
8

9
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.
10
 */
11
export async function main(
12
	auth: Codat,
13
	companyId: string,
14
	connectionId: string,
15
	datasetId: string,
16
	body: { status?: 'Cancel' | 'Process' }
17
) {
18
	const url = new URL(
19
		`https://api.codat.io/companies/${companyId}/connections/${connectionId}/bankStatements/upload/dataset/${datasetId}/endSession`
20
	)
21

22
	const response = await fetch(url, {
23
		method: 'POST',
24
		headers: {
25
			'Content-Type': 'application/json',
26
			Authorization: `Basic ${auth.encodedKey}`
27
		},
28
		body: JSON.stringify(body)
29
	})
30
	if (!response.ok) {
31
		const text = await response.text()
32
		throw new Error(`${response.status} ${text}`)
33
	}
34
	return await response.text()
35
}
36