//native
/**
* Update Purchase Order
* Update a purchase order by ID, e.g. flag it as exported. Field names use dashes, e.g. ship-to-attention.
*/
export async function main(
auth: RT.Coupa,
purchase_order_id: number,
body: { [key: string]: any }
) {
const base = auth.instance_url.replace(/\/+$/, "")
const url = new URL(`${base}/api/purchase_orders/${purchase_order_id}`)
const response = await fetch(url, {
method: "PUT",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify(body),
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
if (response.status === 204) return { success: true }
return await response.json()
}
Submitted by hugo989 3 hours ago