> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sandywp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Trigger a deployment

> Triggers a deployment of the connected repository (async `git_deploy` job; poll the returned deployment's `status` via `GET /api/app/sites/{id}/repositories`). An optional body deploys a specific ref **for this run only**, without changing the repository's configured `branch`. The sandbox must be `ready`, and only one deployment may be in flight per repository at a time.



## OpenAPI

````yaml /openapi.yaml post /api/app/sites/{id}/repositories/{repoId}/deploy
openapi: 3.1.0
info:
  title: SandyWP API
  version: 0.1.0
  summary: Complete supported customer API for SandyWP automation.
  description: >
    This is the complete supported customer API for automating SandyWP
    sandboxes, reusable

    Templates and Blueprints, Imports, Workspaces, account credentials, and
    OAuth connection setup.

    It is the stable HTTP contract for developer integrations; browser,
    provider, and operations

    routes on the same host are deliberately not part of this document.


    **Exclusions ledger.** The specification excludes guest/launcher creation
    (`POST /api/sites`),

    account profile/avatar/password/support and GitHub UI handlers, billing
    checkout/portal/sync,

    public launch routes, plugin/theme search proxies, storage, activity
    telemetry, newsletter,

    health, metrics, impersonation, Slack/GitHub callbacks, Git/Polar webhooks,
    all `/api/admin/**`,

    and all `/api/internal/**` worker or SSH-control routes. Those endpoints are
    browser backends,

    provider callbacks, or operational control-plane interfaces rather than
    supported developer APIs.


    ## Conventions


    - Requests and responses are JSON. Send `Content-Type: application/json` on
    writes (the file
      upload and plugin-ZIP-upload endpoints instead use `multipart/form-data`, as noted on those
      operations).
    - Sandboxes and Templates are addressed by their opaque `id` in the API (for
    example
      `site_abc123`, `tpl_xyz789`).
    - Errors use a consistent envelope — see the `Error` schema. Some actions
    require a paid plan
      and fail with HTTP `402` and a specific error code (for example
      `template_sharing_requires_paid_plan`); each is called out on the operation that returns it.
    - **Async by default.** Provisioning and other slow sandbox mutations happen
    on a worker, not
      inline in the HTTP request. An endpoint that starts one either returns a `jobId` to poll (see
      the `Job` / `JobSummary` schemas and each operation's description), returns the resource in a
      non-terminal state (a site `"creating"`, a Template `"building"`) to re-fetch until it settles,
      or both.
    - A personal bearer token can call the authenticated operations below. A
    scoped OAuth token is
      accepted only by `GET /api/account/me` and the Imports family; it needs `import:read` or
      `import:write` for the matching import operation. Other REST operations treat scoped tokens
      as unauthenticated.
  contact:
    name: SandyWP
    url: https://app.sandywp.com/docs/api
servers:
  - url: https://app.sandywp.com
security:
  - bearerAuth: []
tags:
  - name: Templates
    description: >-
      A Template is a snapshot of a finished sandbox — WordPress/PHP versions,
      plugins, themes, content, and database — ready to restore in seconds.
      Templates come from saving a ready sandbox, and can optionally be
      published as a public "launch this demo" link.
  - name: Sites
    description: >-
      A Site is a disposable WordPress sandbox: its lifecycle
      (create/restore/reset/delete) and the per-sandbox tools built on top of it
      (PHP runtime & ini config, WordPress debug settings, database access,
      outgoing-email capture, plugin deploys, the file manager, Git deployment,
      and SSH access).
  - name: Blueprints
    description: >-
      Reviewable WordPress build recipes that can be validated, saved, run on a
      sandbox, or baked into a Template.
  - name: Imports
    description: >-
      Archive-upload workflows for cloning a live WordPress site or pushing a
      local installation. Scoped OAuth tokens may use only this family, with
      `import:read` for reads and `import:write` for mutations.
  - name: Workspaces
    description: Workspace selection plus member and custom-role administration.
  - name: Account
    description: Identity, usage, personal API tokens, and account SSH public keys.
  - name: OAuth
    description: >-
      Public-client registration and PKCE authorization-code token exchange for
      supported connectors.
paths:
  /api/app/sites/{id}/repositories/{repoId}/deploy:
    post:
      tags:
        - Sites
      summary: Trigger a deployment
      description: >-
        Triggers a deployment of the connected repository (async `git_deploy`
        job; poll the returned deployment's `status` via `GET
        /api/app/sites/{id}/repositories`). An optional body deploys a specific
        ref **for this run only**, without changing the repository's configured
        `branch`. The sandbox must be `ready`, and only one deployment may be in
        flight per repository at a time.
      operationId: triggerRepositoryDeployment
      parameters:
        - $ref: '#/components/parameters/SiteIdParam'
        - $ref: '#/components/parameters/RepositoryIdParam'
        - $ref: '#/components/parameters/WorkspaceHeaderParam'
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                branch:
                  type: string
                  pattern: ^[A-Za-z0-9][A-Za-z0-9._/-]{0,200}$
                  description: >-
                    Ref to deploy for this run only (branch or tag name — the
                    same grammar covers both). Falls back to the repository's
                    configured branch when omitted, unless `refType` is `tag`
                    (which requires an explicit ref).
                refType:
                  $ref: '#/components/schemas/GitDeploymentRefType'
                  description: >-
                    `branch` (default) or `tag` — only affects how the run is
                    labeled in deployment history; the clone itself is identical
                    either way.
      responses:
        '200':
          description: The queued deployment.
          content:
            application/json:
              schema:
                type: object
                required:
                  - deployment
                properties:
                  deployment:
                    $ref: '#/components/schemas/GitDeployment'
        '400':
          description: >-
            `invalid_request` — `branch` fails its grammar check, or `refType:
            "tag"` was sent without a `branch` ref to deploy.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          description: >-
            `repository_not_found` — no such repository, or its sandbox is not
            visible to the caller.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: >-
            `site_not_ready` — the sandbox is not `ready`.
            `deployment_in_progress` — a deployment for this repository is
            already pending/running.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  parameters:
    SiteIdParam:
      name: id
      in: path
      required: true
      description: The sandbox id.
      schema:
        type: string
      example: site_abc123
    RepositoryIdParam:
      name: repoId
      in: path
      required: true
      description: The connected repository id.
      schema:
        type: string
      example: repo_1
    WorkspaceHeaderParam:
      name: X-SandyWP-Workspace
      in: header
      required: false
      description: >-
        Selects which of the caller's workspaces to act in, for accounts
        belonging to more than one (legacy alias: `X-SandyWP-Organization`).
        Defaults to the caller's own personal workspace when omitted. Every id
        in this API (sandboxes, Templates, repositories) is scoped to a single
        workspace, so this header changes which set of resources is visible.
      schema:
        type: string
  schemas:
    GitDeploymentRefType:
      type: string
      enum:
        - branch
        - tag
    GitDeployment:
      type: object
      description: One deployment run (a single clone+sync) of a connected repository.
      required:
        - id
        - repositoryId
        - siteId
        - jobId
        - status
        - trigger
        - branch
        - refType
        - commitSha
        - commitMessage
        - log
        - createdAt
        - updatedAt
      properties:
        id:
          type: string
        repositoryId:
          type: string
        siteId:
          type: string
        jobId:
          type:
            - string
            - 'null'
        status:
          $ref: '#/components/schemas/GitDeploymentStatus'
        trigger:
          $ref: '#/components/schemas/GitDeploymentTrigger'
        branch:
          type:
            - string
            - 'null'
          description: The branch or tag ref this run actually deployed.
        refType:
          $ref: '#/components/schemas/GitDeploymentRefType'
        commitSha:
          type:
            - string
            - 'null'
        commitMessage:
          type:
            - string
            - 'null'
        log:
          type: string
          description: Truncated worker output (capped; see the git deployment guide).
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
    Error:
      type: object
      description: >-
        The standard error envelope returned by every endpoint on a non-2xx
        response.
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              description: >-
                A stable, machine-readable error code (e.g. `invalid_request`,
                `site_not_found`, `plan_limit_reached`). See each operation for
                the codes it can return.
              example: invalid_request
            message:
              type: string
              description: A human-readable message. Safe to display to an end user.
            details:
              type: object
              description: >-
                Optional structured context (e.g. `{"plan": "free", "limit": 2}`
                for a plan-limit error). Omitted entirely on the generic
                internal-error fallback; `{}` when an error has no extra
                context.
              additionalProperties: true
    GitDeploymentStatus:
      type: string
      enum:
        - pending
        - running
        - succeeded
        - failed
    GitDeploymentTrigger:
      type: string
      enum:
        - manual
        - webhook
  responses:
    Unauthorized:
      description: >-
        No valid bearer token was presented, or a scoped OAuth token was used
        outside its allowed Imports and account-identity routes.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: auth_required
              message: A logged-in user is required.
              details: {}
    Forbidden:
      description: >-
        The caller's current workspace Role does not grant the capability this
        action requires.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: capability_required
              message: Your role does not allow this.
              details:
                capability: internals
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Personal API token, sent as `Authorization: Bearer <SANDYWP_API_KEY>`.
        Obtain one from the dashboard account menu (API keys), `sandywp auth
        login`, or `POST /api/account/tokens`. A missing or invalid token
        returns `401 auth_required`. Scoped OAuth tokens are limited to the
        Imports family and `GET /api/account/me`; see the top-level conventions.

````