Edits history of script submission #22778 for ' Create Invoice (coupa)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Create Invoice
     * Create an invoice. Required: invoice-number, invoice-date, supplier, currency, invoice-lines; field names use dashes.
     */
    export async function main(auth: RT.Coupa, body: { [key: string]: any }) {
      const base = auth.instance_url.replace(/\/+$/, "")
      const url = new URL(`${base}/api/invoices`)
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: `Bearer ${auth.token}`,
          "Content-Type": "application/json",
          Accept: "application/json",
        },
        body: JSON.stringify(body),
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      if (response.status === 204) return { success: true }
      return await response.json()
    }
    

    Submitted by hugo989 3 hours ago