1
//native
2
type Xero = {
3
token: string
4
}
5
/**
6
* Retrieves a specific item using a unique item Id
7
*
8
*/
9
export async function main(
10
auth: Xero,
11
ItemID: string,
12
unitdp: string | undefined,
13
xero_tenant_id: string
14
) {
15
const url = new URL(`https://api.xero.com/api.xro/2.0/Items/${ItemID}`)
16
for (const [k, v] of [['unitdp', unitdp]]) {
17
if (v !== undefined && v !== '' && k !== undefined) {
18
url.searchParams.append(k, v)
19
20
21
const response = await fetch(url, {
22
method: 'GET',
23
headers: {
24
Accept: 'application/json',
25
'xero-tenant-id': xero_tenant_id,
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.json()
35
36