//native
type Xero = {
token: string
}
/**
* Uploads a File to a specific folder
*
*/
export async function main(
auth: Xero,
FolderId: string,
xero_tenant_id: string,
Idempotency_Key: string,
body: { body: string; name: string; filename: string; mimeType?: string }
) {
const url = new URL(`https://api.xero.com/files.xro/1.0//Files/${FolderId}`)
const formData = new FormData()
for (const [k, v] of Object.entries(body)) {
if (v !== undefined && v !== '') {
formData.append(k, String(v))
}
}
const response = await fetch(url, {
method: 'POST',
headers: {
Accept: 'application/json',
'xero-tenant-id': xero_tenant_id,
'Idempotency-Key': Idempotency_Key,
Authorization: 'Bearer ' + auth.token
},
body: formData
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 515 days ago