0

Change Invoice Status

by
Published today

Submit a draft invoice for approval, or abandon, void, or dispute an invoice.

Script coupa Verified

The script

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

3
/**
4
 * Change Invoice Status
5
 * Submit a draft invoice for approval, or abandon, void, or dispute an invoice.
6
 */
7
export async function main(
8
  auth: RT.Coupa,
9
  invoice_id: number,
10
  action: "submit" | "abandon" | "void" | "dispute"
11
) {
12
  const base = auth.instance_url.replace(/\/+$/, "")
13
  const url = new URL(`${base}/api/invoices/${invoice_id}/${action}`)
14

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

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

27
  if (response.status === 204) return { success: true }
28
  return await response.json()
29
}
30