0

Create Location

by
Published Nov 5, 2024

Create a Location for a User.

Script enode Verified

The script

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

6
export async function main(
7
	auth: Enode,
8
	userId: string,
9
	body: {
10
		name?: string
11
		latitude?: number
12
		longitude?: number
13
		timezoneName?: string
14
	} & {}
15
) {
16
	const url = new URL(`https://enode-api.production.enode.io/users/${userId}/locations`)
17

18
	const response = await fetch(url, {
19
		method: 'POST',
20
		headers: {
21
			'Content-Type': 'application/json',
22
			Authorization: 'Bearer ' + auth.token
23
		},
24
		body: JSON.stringify(body)
25
	})
26

27
	if (!response.ok) {
28
		const text = await response.text()
29
		throw new Error(`${response.status} ${text}`)
30
	}
31

32
	return await response.json()
33
}
34