//native
type Xero = {
token: string
}
/**
* Updates a timesheet
* Update properties on a single timesheet
*/
export async function main(
auth: Xero,
TimesheetID: string,
Xero_Tenant_Id: string,
Idempotency_Key: string,
body: {
EmployeeID: string
StartDate: string
EndDate: string
Status?: 'DRAFT' | 'PROCESSED' | 'APPROVED' | 'REJECTED' | 'REQUESTED'
Hours?: number
TimesheetID?: string
TimesheetLines?: {
EarningsRateID?: string
TrackingItemID?: string
NumberOfUnits?: number[]
UpdatedDateUTC?: string
}[]
UpdatedDateUTC?: string
ValidationErrors?: { Message?: string }[]
}[]
) {
const url = new URL(`https://api.xero.com/payroll.xro/1.0/Timesheets/${TimesheetID}`)
const response = await fetch(url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Xero-Tenant-Id': Xero_Tenant_Id,
'Idempotency-Key': Idempotency_Key,
'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 515 days ago