Create one or more new projects

Script xero Verified

by hugo697 ยท 12/20/2024

The script

Submitted by hugo697 Bun
Verified 515 days ago
1
//native
2
type Xero = {
3
	token: string
4
}
5
/**
6
 * Create one or more new projects
7
 *
8
 */
9
export async function main(
10
	auth: Xero,
11
	Xero_Tenant_Id: string,
12
	Idempotency_Key: string,
13
	body: {
14
		contactId?: string
15
		name: string
16
		estimateAmount?: number
17
		deadlineUtc?: string
18
	}
19
) {
20
	const url = new URL(`https://api.xero.com/projects.xro/2.0/Projects`)
21

22
	const response = await fetch(url, {
23
		method: 'POST',
24
		headers: {
25
			Accept: 'application/json',
26
			'Xero-Tenant-Id': Xero_Tenant_Id,
27
			'Idempotency-Key': Idempotency_Key,
28
			'Content-Type': 'application/json',
29
			Authorization: 'Bearer ' + auth.token
30
		},
31
		body: JSON.stringify(body)
32
	})
33
	if (!response.ok) {
34
		const text = await response.text()
35
		throw new Error(`${response.status} ${text}`)
36
	}
37
	return await response.json()
38
}
39