Edits history of script submission #9360 for ' Update a category for a specific month (ynab)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Ynab = {
    	token: string
    }
    
    export async function main(
    	auth: Ynab,
    	budget_id: string,
    	month: string,
    	category_id: string,
    	body: { category: { budgeted: number } }
    ) {
    	const url = new URL(
    		`https://api.ynab.com/v1/budgets/${budget_id}/months/${month}/categories/${category_id}`
    	)
    
    	const response = await fetch(url, {
    		method: 'PATCH',
    		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