0

Submit Prepayment Balances

by
Published Apr 8, 2025

Sends the prepayment balances. The partner should do this at least once a day and ideally once per hour. Use the `credentials.access_token` we provided in the [Upsert Installation](#upsert-installation) body to authorize this request.

Script vercel Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Vercel = {
3
  token: string;
4
};
5
/**
6
 * Submit Prepayment Balances
7
 * Sends the prepayment balances. The partner should do this at least once a day and ideally once per hour.  Use the `credentials.access_token` we provided in the [Upsert Installation](#upsert-installation) body to authorize this request.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  integrationConfigurationId: string,
12
  body: {
13
    timestamp: string;
14
    balances: {
15
      resourceId?: string;
16
      credit?: string;
17
      nameLabel?: string;
18
      currencyValueInCents: number;
19
    }[];
20
  },
21
) {
22
  const url = new URL(
23
    `https://api.vercel.com/v1/installations/${integrationConfigurationId}/billing/balance`,
24
  );
25

26
  const response = await fetch(url, {
27
    method: "POST",
28
    headers: {
29
      "Content-Type": "application/json",
30
      Authorization: "Bearer " + auth.token,
31
    },
32
    body: JSON.stringify(body),
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.text();
39
}
40