0

Import Resource

by
Published Apr 8, 2025

This endpoint imports (upserts) a resource to Vercel's installation. This may be needed if resources can be independently created on the partner's side and need to be synchronized to Vercel.

Script vercel Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Vercel = {
3
  token: string;
4
};
5
/**
6
 * Import Resource
7
 * This endpoint imports (upserts) a resource to Vercel's installation. This may be needed if resources can be independently created on the partner's side and need to be synchronized to Vercel.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  integrationConfigurationId: string,
12
  resourceId: string,
13
  body: {
14
    productId: string;
15
    name: string;
16
    status:
17
      | "ready"
18
      | "pending"
19
      | "suspended"
20
      | "resumed"
21
      | "uninstalled"
22
      | "error";
23
    metadata?: {};
24
    billingPlan?: {
25
      id: string;
26
      type: "prepayment" | "subscription";
27
      name: string;
28
      paymentMethodRequired?: false | true;
29
    };
30
    notification?: {
31
      level: "error" | "info" | "warn";
32
      title: string;
33
      message?: string;
34
      href?: string;
35
    };
36
    secrets?: { name: string; value: string; prefix?: string }[];
37
  },
38
) {
39
  const url = new URL(
40
    `https://api.vercel.com/v1/installations/${integrationConfigurationId}/resources/${resourceId}`,
41
  );
42

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