0

Get Invoice

by
Published today

Retrieve a single invoice by its Coupa internal ID.

Script coupa Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 2 hours ago
1
//native
2

3
/**
4
 * Get Invoice
5
 * Retrieve a single invoice by its Coupa internal ID.
6
 */
7
export async function main(
8
  auth: RT.Coupa,
9
  invoice_id: number,
10
  return_object: "limited" | "shallow" | undefined
11
) {
12
  const base = auth.instance_url.replace(/\/+$/, "")
13
  const url = new URL(`${base}/api/invoices/${invoice_id}`)
14
  if (return_object !== undefined && return_object !== "") {
15
    url.searchParams.append("return_object", return_object)
16
  }
17

18
  const response = await fetch(url, {
19
    headers: {
20
      Authorization: `Bearer ${auth.token}`,
21
      Accept: "application/json",
22
    },
23
  })
24

25
  if (!response.ok) {
26
    throw new Error(`${response.status} ${await response.text()}`)
27
  }
28

29
  return await response.json()
30
}
31