Create Asset Metadata
One script reply has been approved by the moderators Verified

Create a new asset entry. This endpoint generates a response with the following information: uploadUrl and uploadDetails. You can use these two properties to upload the file to Amazon s3 by making a POST request to the uploadUrl with the uploadDetails object as your header information in the request. Required scope | assets:write

Created by hugo697 514 days ago
Submitted by hugo697 Bun
Verified 514 days ago
1
//native
2
type Webflow = {
3
	token: string
4
}
5

6
export async function main(
7
	auth: Webflow,
8
	site_id: string,
9
	body: { fileName: string; fileHash: string; parentFolder?: string }
10
) {
11
	const url = new URL(`https://api.webflow.com/v2/sites/${site_id}/assets`)
12

13
	const response = await fetch(url, {
14
		method: 'POST',
15
		headers: {
16
			'Content-Type': 'application/json',
17
			Authorization: 'Bearer ' + auth.token
18
		},
19
		body: JSON.stringify(body)
20
	})
21

22
	if (!response.ok) {
23
		const text = await response.text()
24
		throw new Error(`${response.status} ${text}`)
25
	}
26

27
	return await response.json()
28
}
29