0

Detach the Figma attachment from a key

by
Published Oct 17, 2025

Detach the Figma attachment from a key

Script phrase Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Phrase = {
3
	token: string
4
	baseUrl: string
5
}
6
/**
7
 * Detach the Figma attachment from a key
8
 * Detach the Figma attachment from a key
9
 */
10
export async function main(
11
	auth: Phrase,
12
	project_id: string,
13
	figma_attachment_id: string,
14
	id: string,
15
	branch: string | undefined
16
) {
17
	const url = new URL(
18
		`${auth.baseUrl}/projects/${project_id}/figma_attachments/${figma_attachment_id}/keys/${id}`
19
	)
20
	for (const [k, v] of [['branch', branch]]) {
21
		if (v !== undefined && v !== '' && k !== undefined) {
22
			url.searchParams.append(k, v)
23
		}
24
	}
25
	const response = await fetch(url, {
26
		method: 'DELETE',
27
		headers: {
28
			Authorization: 'ApiToken ' + auth.token
29
		},
30
		body: undefined
31
	})
32
	if (!response.ok) {
33
		const text = await response.text()
34
		throw new Error(`${response.status} ${text}`)
35
	}
36
	return await response.text()
37
}
38