0

Update a category for a specific month

by
Published Nov 5, 2024

Update a category for a specific month. Only `budgeted` amount can be updated.

Script ynab Verified

The script

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

6
export async function main(
7
	auth: Ynab,
8
	budget_id: string,
9
	month: string,
10
	category_id: string,
11
	body: { category: { budgeted: number } }
12
) {
13
	const url = new URL(
14
		`https://api.ynab.com/v1/budgets/${budget_id}/months/${month}/categories/${category_id}`
15
	)
16

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

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

31
	return await response.json()
32
}
33