//native
type Webflow = {
token: string
}
export async function main(
auth: Webflow,
site_id: string,
offset: string | undefined,
limit: string | undefined,
sort:
| 'CreatedOn'
| '-CreatedOn'
| 'Email'
| '-Email'
| 'Status'
| '-Status'
| 'LastLogin'
| '-LastLogin'
| 'UpdatedOn'
| '-UpdatedOn'
| undefined
) {
const url = new URL(`https://api.webflow.com/v2/sites/${site_id}/users`)
for (const [k, v] of [
['offset', offset],
['limit', limit],
['sort', sort]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: 'Bearer ' + auth.token
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 514 days ago