# Deploy a service

Source: https://openpanel.sh/docs/api/deployments/deploy-a-service

Deploys the service as it is set now: an image at once; a Git source once it is built (status queued, then building). Variables and settings are taken as they are at this moment.

`POST https://openpanel.sh/api/v1/services/{serviceId}/deployments`

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `serviceId` | path | yes | The service's id. |
| `Idempotency-Key` | header | no | Any unique string up to 255 characters. Sending the same request again with it returns the first answer instead of creating twice. |

## Request body

JSON, `DeploymentCreate`.

## Responses

| Status | Meaning | Body |
|---|---|---|
| 201 | Deploy a service | `application/json`, `Deployment` |
| 401 | No valid credential was sent. | `application/problem+json`, `Problem` |
| 403 | The credential may not do this. | `application/problem+json`, `Problem` |
| 404 | Not found, or not visible to this credential. | `application/problem+json`, `Problem` |
| 409 | It clashes with something that exists, such as a name in use. | `application/problem+json`, `Problem` |
| 422 | The input was refused; detail says why. | `application/problem+json`, `Problem` |
| 429 | Too many requests; wait for Retry-After seconds. | `application/problem+json`, `Problem` |

## Schemas

### Deployment

```json
{
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "serviceId": {
      "type": "string",
      "format": "uuid"
    },
    "projectId": {
      "type": "string",
      "format": "uuid"
    },
    "status": {
      "type": "string",
      "enum": [
        "queued",
        "building",
        "deploying",
        "running",
        "failed",
        "superseded",
        "cancelled"
      ]
    },
    "commit": {
      "type": [
        "string",
        "null"
      ]
    },
    "image": {
      "type": [
        "string",
        "null"
      ]
    },
    "config": {
      "type": "object",
      "propertyNames": {
        "type": "string"
      },
      "additionalProperties": {},
      "description": "The service's settings when this deployment was made, and where each replica runs."
    },
    "rollbackOf": {
      "anyOf": [
        {
          "type": "string",
          "format": "uuid"
        },
        {
          "type": "null"
        }
      ]
    },
    "error": {
      "type": [
        "string",
        "null"
      ]
    },
    "createdBy": {
      "type": [
        "string",
        "null"
      ]
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "finishedAt": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "id",
    "serviceId",
    "projectId",
    "status",
    "commit",
    "image",
    "config",
    "rollbackOf",
    "error",
    "createdBy",
    "createdAt",
    "finishedAt"
  ]
}
```

### DeploymentCreate

```json
{
  "type": "object",
  "properties": {
    "commit": {
      "description": "For a Git source: the commit to build. Default the branch's latest.",
      "type": "string",
      "maxLength": 64
    }
  },
  "additionalProperties": false
}
```

### Problem

```json
{
  "type": "object",
  "properties": {
    "type": {
      "type": "string",
      "description": "A link to the error's explanation in the docs."
    },
    "title": {
      "type": "string"
    },
    "status": {
      "type": "integer"
    },
    "code": {
      "type": "string",
      "description": "Stable machine-readable code: not_found, forbidden, invalid, conflict, rate_limited, not_implemented, …"
    },
    "detail": {
      "type": "string",
      "description": "What went wrong, in a sentence written for a person."
    }
  },
  "required": [
    "type",
    "title",
    "status",
    "code",
    "detail"
  ]
}
```