0

Create Supplier

by
Published today

Create a supplier. Only name is required; field names use dashes, e.g. display-name, po-email, primary-contact.

Script coupa Verified

The script

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

3
/**
4
 * Create Supplier
5
 * Create a supplier. Only name is required; field names use dashes, e.g. display-name, po-email, primary-contact.
6
 */
7
export async function main(auth: RT.Coupa, body: { [key: string]: any }) {
8
  const base = auth.instance_url.replace(/\/+$/, "")
9
  const url = new URL(`${base}/api/suppliers`)
10

11
  const response = await fetch(url, {
12
    method: "POST",
13
    headers: {
14
      Authorization: `Bearer ${auth.token}`,
15
      "Content-Type": "application/json",
16
      Accept: "application/json",
17
    },
18
    body: JSON.stringify(body),
19
  })
20

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

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