1 | |
2 | type Ynab = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Ynab, |
8 | budget_id: string, |
9 | payee_id: string, |
10 | body: { payee: { name?: string } } |
11 | ) { |
12 | const url = new URL(`https://api.ynab.com/v1/budgets/${budget_id}/payees/${payee_id}`) |
13 |
|
14 | const response = await fetch(url, { |
15 | method: 'PATCH', |
16 | headers: { |
17 | 'Content-Type': 'application/json', |
18 | Authorization: 'Bearer ' + auth.token |
19 | }, |
20 | body: JSON.stringify(body) |
21 | }) |
22 |
|
23 | if (!response.ok) { |
24 | const text = await response.text() |
25 | throw new Error(`${response.status} ${text}`) |
26 | } |
27 |
|
28 | return await response.json() |
29 | } |
30 |
|