//native
type Xero = {
token: string
}
/**
* Retrieves all time entries associated with a specific project
* Allows you to retrieve the time entries associated with a specific project
*/
export async function main(
auth: Xero,
projectId: string,
userId: string | undefined,
taskId: string | undefined,
invoiceId: string | undefined,
contactId: string | undefined,
page: string | undefined,
pageSize: string | undefined,
states: string | undefined,
isChargeable: string | undefined,
dateAfterUtc: string | undefined,
dateBeforeUtc: string | undefined,
Xero_Tenant_Id: string
) {
const url = new URL(`https://api.xero.com/projects.xro/2.0/Projects/${projectId}/Time`)
for (const [k, v] of [
['userId', userId],
['taskId', taskId],
['invoiceId', invoiceId],
['contactId', contactId],
['page', page],
['pageSize', pageSize],
['states', states],
['isChargeable', isChargeable],
['dateAfterUtc', dateAfterUtc],
['dateBeforeUtc', dateBeforeUtc]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
Accept: 'application/json',
'Xero-Tenant-Id': Xero_Tenant_Id,
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 515 days ago