0
Retrieves a specific attachment from a specific contact using a unique attachment Id
One script reply has been approved by the moderators Verified
Created by hugo697 127 days ago Viewed 11494 times
0
Submitted by hugo697 Bun
Verified 127 days ago
1
//native
2
type Xero = {
3
  token: string;
4
};
5
/**
6
 * Retrieves a specific attachment from a specific contact using a unique attachment Id
7
 *
8
 */
9
export async function main(
10
  auth: Xero,
11
  ContactID: 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/Contacts/${ContactID}/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