0

Delete an item from a file array

by
Published Apr 8, 2025

Deletes an item from an file array column given the file ID

Script xata Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Xata = {
3
	apiKey: string
4
	workspaceUrl: string
5
}
6
/**
7
 * Delete an item from a file array
8
 * Deletes an item from an file array column given the file ID
9
 */
10
export async function main(
11
	auth: Xata,
12
	db_branch_name: string,
13
	table_name: string,
14
	record_id: string,
15
	column_name: string,
16
	file_id: string
17
) {
18
	const url = new URL(
19
		`${auth.workspaceUrl}/db/${db_branch_name}/tables/${table_name}/data/${record_id}/column/${column_name}/file/${file_id}`
20
	)
21

22
	const response = await fetch(url, {
23
		method: 'DELETE',
24
		headers: {
25
			Authorization: 'Bearer ' + auth.apiKey
26
		},
27
		body: undefined
28
	})
29
	if (!response.ok) {
30
		const text = await response.text()
31
		throw new Error(`${response.status} ${text}`)
32
	}
33
	return await response.json()
34
}
35