Edits history of script submission #22783 for ' Get Invoice (coupa)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Get Invoice
     * Retrieve a single invoice by its Coupa internal ID.
     */
    export async function main(
      auth: RT.Coupa,
      invoice_id: number,
      return_object: "limited" | "shallow" | undefined
    ) {
      const base = auth.instance_url.replace(/\/+$/, "")
      const url = new URL(`${base}/api/invoices/${invoice_id}`)
      if (return_object !== undefined && return_object !== "") {
        url.searchParams.append("return_object", return_object)
      }
    
      const response = await fetch(url, {
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 3 hours ago