Retrieves fixed asset by id

By passing in the appropriate asset id, you can search for a specific fixed asset in the system

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 fixed asset by id
7
 * By passing in the appropriate asset id, you can search for
8
a specific fixed asset in the system
9

10
 */
11
export async function main(auth: Xero, id: string, xero_tenant_id: string) {
12
  const url = new URL(`https://api.xero.com/assets.xro/1.0/Assets/${id}`);
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