1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Get revenue by contacts report |
7 | * The revenue by contact report provides a year to date profit and loss for customers and suppliers for a given organisation, including detailed contact information. |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | contactIds: string | undefined, |
12 | includeManualJournals: string | undefined, |
13 | startDate: string | undefined, |
14 | endDate: string | undefined, |
15 | xero_tenant_id: string |
16 | ) { |
17 | const url = new URL(`https://api.xero.com/finance.xro/1.0/FinancialStatements/contacts/revenue`) |
18 | for (const [k, v] of [ |
19 | ['contactIds', contactIds], |
20 | ['includeManualJournals', includeManualJournals], |
21 | ['startDate', startDate], |
22 | ['endDate', endDate] |
23 | ]) { |
24 | if (v !== undefined && v !== '' && k !== undefined) { |
25 | url.searchParams.append(k, v) |
26 | } |
27 | } |
28 | const response = await fetch(url, { |
29 | method: 'GET', |
30 | headers: { |
31 | Accept: 'application/json', |
32 | 'xero-tenant-id': xero_tenant_id, |
33 | Authorization: 'Bearer ' + auth.token |
34 | }, |
35 | body: undefined |
36 | }) |
37 | if (!response.ok) { |
38 | const text = await response.text() |
39 | throw new Error(`${response.status} ${text}`) |
40 | } |
41 | return await response.json() |
42 | } |
43 |
|