//native
type Ynab = {
token: string
}
export async function main(
auth: Ynab,
budget_id: string,
body: {
account: {
name: string
type:
| 'checking'
| 'savings'
| 'cash'
| 'creditCard'
| 'lineOfCredit'
| 'otherAsset'
| 'otherLiability'
| 'mortgage'
| 'autoLoan'
| 'studentLoan'
| 'personalLoan'
| 'medicalDebt'
| 'otherDebt'
balance: number
}
}
) {
const url = new URL(`https://api.ynab.com/v1/budgets/${budget_id}/accounts`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.token
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 581 days ago