Retrieves history for a specific item

Script xero Verified

by hugo697 ยท 12/20/2024

The script

Submitted by hugo697 Bun
Verified 515 days ago
1
//native
2
type Xero = {
3
  token: string;
4
};
5
/**
6
 * Retrieves history for a specific item
7
 *
8
 */
9
export async function main(auth: Xero, ItemID: string, xero_tenant_id: string) {
10
  const url = new URL(
11
    `https://api.xero.com/api.xro/2.0/Items/${ItemID}/History`,
12
  );
13

14
  const response = await fetch(url, {
15
    method: "GET",
16
    headers: {
17
      Accept: 'application/json',
18
      "xero-tenant-id": xero_tenant_id,
19
      Authorization: "Bearer " + auth.token,
20
    },
21
    body: undefined,
22
  });
23
  if (!response.ok) {
24
    const text = await response.text();
25
    throw new Error(`${response.status} ${text}`);
26
  }
27
  return await response.json();
28
}
29