typescriptintermediate
Vercel API — Trigger and List Deployments
Use the Vercel REST API to trigger deployments, list recent builds, and check deployment status.
typescriptPress ⌘/Ctrl + Shift + C to copy
const VERCEL_TOKEN = process.env.VERCEL_TOKEN!;
const PROJECT_ID = process.env.VERCEL_PROJECT_ID!;
interface Deployment {
uid: string;
url: string;
state: 'READY' | 'ERROR' | 'BUILDING' | 'QUEUED';
created: number;
}
async function vercelFetch<T>(path: string, init?: RequestInit): Promise<T> {
const res = await fetch(`https://api.vercel.com${path}`, {
...init,
headers: {
Authorization: `Bearer ${VERCEL_TOKEN}`,
'Content-Type': 'application/json',
...init?.headers,
},
});
if (!res.ok) throw new Error(`Vercel API ${res.status}: ${await res.text()}`);
return res.json();
}
// List recent deployments
async function listDeployments(limit = 5): Promise<Deployment[]> {
const { deployments } = await vercelFetch<{ deployments: Deployment[] }>(
`/v6/deployments?projectId=${PROJECT_ID}&limit=${limit}`
);
return deployments;
}
// Trigger a redeployment
async function redeploy(deploymentId: string): Promise<Deployment> {
return vercelFetch<Deployment>('/v13/deployments', {
method: 'POST',
body: JSON.stringify({
name: PROJECT_ID,
deploymentId,
target: 'production',
}),
});
}
// Check deployment status
async function getStatus(deploymentId: string): Promise<string> {
const { state } = await vercelFetch<Deployment>(
`/v13/deployments/${deploymentId}`
);
return state;
}Use Cases
- Triggering deployments from CI or Slack bots
- Monitoring deployment status programmatically
- Building internal deployment dashboards
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
yamlintermediate
GitHub Actions — Deploy to Cloudflare Pages
Automated deployment pipeline to Cloudflare Pages with build preview for PRs and production on main.
Best for: Zero-config deployment for static Next.js exports
#github-actions#cloudflare
yamlintermediate
Kubernetes Deployment Manifest
Production-ready Kubernetes deployment with resource limits, probes, rolling updates, and anti-affinity.
Best for: Deploying containerized applications to Kubernetes
#kubernetes#deployment
typescriptintermediate
AWS SDK v3 — S3 Operations in TypeScript
Perform S3 operations with AWS SDK v3: upload, download, list, presigned URLs, and multipart upload.
Best for: Server-side file uploads to S3
#aws#s3
typescriptintermediate
Request Validation Schema Builder
Build a lightweight request validation layer with type inference for API endpoints.
Best for: API request body validation
#nodejs#validation