0

Submit Invoice

Published Apr 8, 2025

This endpoint allows the partner to submit an invoice to Vercel.

Script vercel Verified

The script

Submitted by hugo697 Bun
Verified 581 days ago
1
//native
2
type Vercel = {
3
  token: string;
4
};
5
/**
6
 * Submit Invoice
7
 * This endpoint allows the partner to submit an invoice to Vercel.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  integrationConfigurationId: string,
12
  body: {
13
    externalId?: string;
14
    invoiceDate: string;
15
    memo?: string;
16
    period: { start: string; end: string };
17
    items: {
18
      resourceId?: string;
19
      billingPlanId: string;
20
      start?: string;
21
      end?: string;
22
      name: string;
23
      details?: string;
24
      price: string;
25
      quantity: number;
26
      units: string;
27
      total: string;
28
    }[];
29
    discounts?: {
30
      resourceId?: string;
31
      billingPlanId: string;
32
      start?: string;
33
      end?: string;
34
      name: string;
35
      details?: string;
36
      amount: string;
37
    }[];
38
    test?: { validate?: false | true; result?: "paid" | "notpaid" };
39
  },
40
) {
41
  const url = new URL(
42
    `https://api.vercel.com/v1/installations/${integrationConfigurationId}/billing/invoices`,
43
  );
44

45
  const response = await fetch(url, {
46
    method: "POST",
47
    headers: {
48
      "Content-Type": "application/json",
49
      Authorization: "Bearer " + auth.token,
50
    },
51
    body: JSON.stringify(body),
52
  });
53
  if (!response.ok) {
54
    const text = await response.text();
55
    throw new Error(`${response.status} ${text}`);
56
  }
57
  return await response.json();
58
}
59