1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Retrieves specific attachments from a specific BankTransaction using a unique attachment Id |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | BankTransactionID: string, |
12 | AttachmentID: string, |
13 | xero_tenant_id: string, |
14 | contentType: string |
15 | ) { |
16 | const url = new URL( |
17 | `https://api.xero.com/api.xro/2.0/BankTransactions/${BankTransactionID}/Attachments/${AttachmentID}` |
18 | ) |
19 |
|
20 | const response = await fetch(url, { |
21 | method: 'GET', |
22 | headers: { |
23 | Accept: 'application/json', |
24 | 'xero-tenant-id': xero_tenant_id, |
25 | contentType: contentType, |
26 | Authorization: 'Bearer ' + auth.token |
27 | }, |
28 | body: undefined |
29 | }) |
30 | if (!response.ok) { |
31 | const text = await response.text() |
32 | throw new Error(`${response.status} ${text}`) |
33 | } |
34 | return await response.text() |
35 | } |
36 |
|