List Orders

List all orders created for a given site. Required scope | `ecommerce:read`

Script webflow Verified

by hugo697 ยท 11/5/2024

The script

Submitted by hugo697 Bun
Verified 564 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
	status:
10
		| 'pending'
11
		| 'refunded'
12
		| 'dispute-lost'
13
		| 'fulfilled'
14
		| 'disputed'
15
		| 'unfulfilled'
16
		| undefined,
17
	offset: string | undefined,
18
	limit: string | undefined
19
) {
20
	const url = new URL(`https://api.webflow.com/v2/sites/${site_id}/orders`)
21

22
	for (const [k, v] of [
23
		['status', status],
24
		['offset', offset],
25
		['limit', limit]
26
	]) {
27
		if (v !== undefined && v !== '' && k !== undefined) {
28
			url.searchParams.append(k, v)
29
		}
30
	}
31

32
	const response = await fetch(url, {
33
		method: 'GET',
34
		headers: {
35
			Authorization: 'Bearer ' + auth.token
36
		},
37
		body: undefined
38
	})
39

40
	if (!response.ok) {
41
		const text = await response.text()
42
		throw new Error(`${response.status} ${text}`)
43
	}
44

45
	return await response.json()
46
}
47