1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Creates one or more new statements |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | Xero_Tenant_Id: string, |
12 | Idempotency_Key: string, |
13 | body: { |
14 | pagination?: { |
15 | page?: number |
16 | pageSize?: number |
17 | pageCount?: number |
18 | itemCount?: number |
19 | } |
20 | items?: { |
21 | id?: string |
22 | feedConnectionId?: string |
23 | status?: 'PENDING' | 'REJECTED' | 'DELIVERED' |
24 | startDate?: string |
25 | endDate?: string |
26 | startBalance?: { |
27 | amount?: number |
28 | creditDebitIndicator?: 'CREDIT' | 'DEBIT' |
29 | } |
30 | endBalance?: { |
31 | amount?: number |
32 | creditDebitIndicator?: 'CREDIT' | 'DEBIT' |
33 | } |
34 | statementLines?: { |
35 | postedDate?: string |
36 | description?: string |
37 | amount?: number |
38 | creditDebitIndicator?: 'CREDIT' | 'DEBIT' |
39 | transactionId?: string |
40 | payeeName?: string |
41 | reference?: string |
42 | chequeNumber?: string |
43 | transactionType?: string |
44 | }[] |
45 | errors?: { |
46 | title?: string |
47 | status?: number |
48 | detail?: string |
49 | type?: |
50 | | 'invalid-request' |
51 | | 'invalid-application' |
52 | | 'invalid-feed-connection' |
53 | | 'duplicate-statement' |
54 | | 'invalid-end-balance' |
55 | | 'invalid-start-and-end-date' |
56 | | 'invalid-start-date' |
57 | | 'internal-error' |
58 | | 'feed-already-connected-in-current-organisation' |
59 | | 'invalid-end-date' |
60 | | 'statement-not-found' |
61 | | 'feed-connected-in-different-organisation' |
62 | | 'feed-already-connected-in-different-organisation' |
63 | | 'bank-feed-not-found' |
64 | | 'invalid-country-specified' |
65 | | 'invalid-organisation-bank-feeds' |
66 | | 'invalid-organisation-multi-currency' |
67 | | 'invalid-feed-connection-for-organisation' |
68 | | 'invalid-user-role' |
69 | | 'account-not-valid' |
70 | | 'feed-not-found-or-already-deleted' |
71 | }[] |
72 | statementLineCount?: number |
73 | }[] |
74 | } |
75 | ) { |
76 | const url = new URL(`https://api.xero.com/bankfeeds.xro/1.0/Statements`) |
77 |
|
78 | const response = await fetch(url, { |
79 | method: 'POST', |
80 | headers: { |
81 | Accept: 'application/json', |
82 | 'Xero-Tenant-Id': Xero_Tenant_Id, |
83 | 'Idempotency-Key': Idempotency_Key, |
84 | 'Content-Type': 'application/json', |
85 | Authorization: 'Bearer ' + auth.token |
86 | }, |
87 | body: JSON.stringify(body) |
88 | }) |
89 | if (!response.ok) { |
90 | const text = await response.text() |
91 | throw new Error(`${response.status} ${text}`) |
92 | } |
93 | return await response.json() |
94 | } |
95 |
|