//native
/**
* List of timesheets
* Retrieve a list of timesheets in your Deel account. You can filter the list by providing additional paramters e.g. contract_id, contract_type etc.
**Token scopes**: `timesheets:read`
*/
export async function main(
auth: RT.Deel,
contract_id?: string | undefined,
contract_types?: string | undefined,
statuses?: string | undefined,
reporter_id?: string | undefined,
date_from?: string | undefined,
date_to?: string | undefined,
limit?: string | undefined,
offset?: string | undefined
) {
const url = new URL(`https://api.letsdeel.com/rest/v2/timesheets`)
for (const [k, v] of [
['contract_id', contract_id],
['contract_types', contract_types],
['statuses', statuses],
['reporter_id', reporter_id],
['date_from', date_from],
['date_to', date_to],
['limit', limit],
['offset', offset]
]) {
if (v !== undefined && v !== '') {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: 'Bearer ' + auth.apiKey
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 235 days ago