---
title: "Create or update the preview of a Git branch (Git-backed or managed projects); redeploys it if it already exists"
method: POST
path: "/projects/{projectId}/previews"
tags: ["Previews"]
---

# Create or update the preview of a Git branch (Git-backed or managed projects); redeploys it if it already exists

`POST /projects/{projectId}/previews`

## Request

- Base URL: `https://hostingsurge.com/api/v1`
- URL: `https://hostingsurge.com/api/v1/projects/{projectId}/previews`
- Auth: one of:
  - HTTP bearer
  - API key in cookie `__Host-hs_session`

## Path parameters

- `projectId` string, uuid, required

## Request body

- object
  - `branch` string, required: Git branch to track (Git-backed projects) or a free-form label (upload/CLI previews)
  - `ref` string: Commit SHA to deploy; default = the branch head (Git-backed projects only)

## Response `201`

Created or updated

- object
  - `id` string, uuid, required
  - `projectId` string, uuid, required
  - `branch` string, required: Git branch tracked, or the free-form label of an upload preview
  - `hostname` string, required
  - `url` string, nullable, required
  - `status` 'provisioning' | 'ready' | 'error' | 'deleting', required
  - `statusDetail` string, nullable, required
  - `latestDeployment` object, nullable, required
    - `id` string, uuid, required
    - `state` 'queued' | 'building' | 'deploying' | 'ready' | 'error' | 'canceled', required
    - `createdAt` string, required: ISO-8601 timestamp
    - `readyAt` string, nullable, required: ISO-8601 timestamp
    - `commitSha` string, nullable, required
    - `commitMessage` string, nullable, required
    - `branch` string, nullable, required
    - `trigger` 'create' | 'redeploy' | 'git_push' | 'api' | 'cli' | 'upload' | 'rollback' | 'config_change' | 'builder' | 'promote' | 'deploy_hook', required
  - `lastDeployedAt` string, nullable, required: ISO-8601 timestamp
  - `lastActivityAt` string, required: Bumped on every deploy/redeploy; drives idle expiry
  - `expiresAt` string, nullable, required: Estimate at the platform's current idle-preview setting; redeploying resets it
  - `createdAt` string, required: ISO-8601 timestamp
  - `updatedAt` string, required: ISO-8601 timestamp

## Other responses

- `400`: Invalid request (code invalid_request)
- `401`: Missing or invalid session/token (code unauthorized)
- `402`: A plan/platform preview limit was reached (code limit_reached)
- `403`: Authenticated but not permitted (code forbidden)
- `404`: Not found or not visible to the caller (code not_found)
- `409`: Conflicting state (code conflict)
- `429`: Too many requests (code rate_limited); see Retry-After
- `501`: Preview deployments are not configured on this server yet (code not_configured)

---

[API](https://skmtc.dev/hostingsurge/apis/hostingsurge-platform-api.md) · [All operations](https://skmtc.dev/hostingsurge/apis/hostingsurge-platform-api/llms.txt) · [OpenAPI document](https://skmtc.dev/hostingsurge/apis/hostingsurge-platform-api/revisions/4d08337cdff1?raw)
