//native
type Ynab = {
token: string
}
export async function main(
auth: Ynab,
budget_id: string,
month: string,
since_date: string | undefined,
type: 'uncategorized' | 'unapproved' | undefined,
last_knowledge_of_server: string | undefined
) {
const url = new URL(`https://api.ynab.com/v1/budgets/${budget_id}/months/${month}/transactions`)
for (const [k, v] of [
['since_date', since_date],
['type', type],
['last_knowledge_of_server', last_knowledge_of_server]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: 'Bearer ' + auth.token
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 581 days ago