# Save staged source as one commit

Commit only the staged tree. Keep other pending changes. Reject a moved project branch. Configured automatic deployment may start a build.

## POST `/v1/spaces/{spaceId}/source/workspaces/{workspaceId}/commit`

### Authorization

`Authorization` Bearer token · header required

`Authorization: Bearer <token>` with an API key (`sfa_` prefix), an OAuth access token, a session token, or a Space machine credential (`sfm_` prefix).

or

`Authorization` OAuth2 access token · header required

OAuth 2.0 with Spacefast scopes. People use the authorization code flow; machines use client credentials.

Scopes: `spaces:write` `spaces:read`

### Path parameters

- `spaceId` string required
- `workspaceId` string required

### Request body

required `application/json`

- `expectedRevision` integer required
  - Revision from the last workspace response. Read the workspace again after a revision conflict.
  - min 0 · max 9007199254740991

- `operationId` string required
  - Unique ID for this operation. Reuse this ID and the same input after an uncertain response.
  - min length 1 · max length 128

- `message` string required
  - min length 1 · max length 4096

- `author` object
  - Omit to reuse the author stored when the workspace was created.

- `name` string required
      - min length 1
    - `email` string <email> required
      - matches `^(?!\.)(?!.*\.\.)([A-Za-z0-9\'+\-\.]*[A-Za-z0-9\_+-]@[A-Za-z0-9][A-Za-z0-9\-]*\.[A-Za-z]{2,})$`

### Responses

#### 200 Response for status 200

- `$schema` string <uri>
  - Canonical JSON Schema URL for this response body. The server also sends it in the `Link: rel="describedby"` response header.

- `data` object required

- `workspace` object required

- `id` string required
        - `spaceId` string required
        - `repositoryId` string required
        - `targetBranch` string required
        - `name` string required
        - `revision` integer required
          - min 0 · max 9007199254740991
        - `state` string required
          - Allowed: `initializing` `active` `conflicted` `closed`
        - `baseCommitSha` string | any required
        - `indexCommitSha` string | any required
        - `workingCommitSha` string | any required
        - `headCommitSha` string | any required
        - `originalUploadVersionId` string | any required
        - `hasStagedChanges` boolean required
        - `hasUnstagedChanges` boolean required
        - `hasPendingChanges` boolean required
        - `needsSync` boolean required
        - `pendingOperationId` string | any required
        - `autoDeploy` boolean required
        - `createdAt` string required
        - `updatedAt` string required

- `commit` object

- `sourceCommitSha` string required
          - matches `^[a-f0-9]{40}$`
        - `parentSourceCommitSha` string required
          - matches `^[a-f0-9]{40}$`
        - `message` string required
        - `autoDeploy` boolean required

- `conflicts` object

- `phase` string required
          - Allowed: `staged` `working` `undo`
        - `labels` object required

- `ours` string required
            - `theirs` string required
        - `files` object[] required
          - Array of `object`

- `path` string required
            - `result` string required
            - `base` object required

- `sourceCommitSha` string required
                  - matches `^[a-f0-9]{40}$`
                - `content` string | any required
                - `exists` boolean required
                - `binary` boolean required
                - `truncated` boolean required
                - `ours` object required

- `sourceCommitSha` string required
                      - matches `^[a-f0-9]{40}$`
                    - `content` string | any required
                    - `exists` boolean required
                    - `binary` boolean required
                    - `truncated` boolean required
                - `theirs` object required

- `sourceCommitSha` string required
                      - matches `^[a-f0-9]{40}$`
                    - `content` string | any required
                    - `exists` boolean required
                    - `binary` boolean required
                    - `truncated` boolean required

### default Problem details (RFC 9457). Any 4xx/5xx response is one `application/problem+json` document.

- `$schema` string <uri>
  - Canonical JSON Schema URL for this response body. The server also sends it in the `Link: rel="describedby"` response header.

- `type` string required
  - URL of the documentation page for this error. Derived from `code`.
- `title` string required
  - Human-readable name of the error type. Derived from `code`.
- `status` integer required
  - HTTP status of the response, repeated in the body.
  - min -9007199254740991 · max 9007199254740991
- `detail` string required
  - What went wrong in this request.
- `code` string required
  - Stable snake_case error code. Match on this, not on `detail`.
- `pointer` string
  - RFC 6901 JSON Pointer to the request field or batch entry that failed, for example `/files/37/path`. Present on validation failures.
- `details` object
  - Machine-readable context keyed by the error code.
- `suggestions` string[]
  - Recovery steps safe to show to a person.
- `next` string[]
  - Commands or API requests to run next, usable as written.
- `requestId` string required
  - ID of this request, from the `X-Request-Id` header or generated. Quote it when contacting support.

### Try it

#### Server

Base URL https://api.spacefast.com

Custom base URL Overrides the selected server when set.

### Authorization

Bearer token Remember on this device

### Include my values in samples

### Parameters

- `spaceId` path* `workspaceId` path*

### Body application/json

### Request body

### Send Request

### cURL

```bash
curl -X POST "https://api.spacefast.com/v1/spaces/string/source/workspaces/string/commit" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \ 
  -d '{\
  "expectedRevision": 9007199254740991,\
  "operationId": "string",\
  "message": "string",\
  "author": {\
    "name": "string",\
    "email": "user@example.com"\
  }\
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.spacefast.com/v1/spaces/string/source/workspaces/string/commit", {
  method: "POST",
  headers: {
    "Authorization": "Bearer YOUR_TOKEN",
    "Content-Type": "application/json"
  },
  body: "{\
  \"expectedRevision\": 9007199254740991,\
  \"operationId\": \"string\",\
  \"message\": \"string\",\
  \"author\": {\
    \"name\": \"string\",\
    \"email\": \"user@example.com\"\
  }\
}"
});
```

### Python

```python
import requests

response = requests.post(
    "https://api.spacefast.com/v1/spaces/string/source/workspaces/string/commit",
    headers={
        "Authorization": "Bearer YOUR_TOKEN",
        "Content-Type": "application/json"
    },
    data="{\
  \"expectedRevision\": 9007199254740991,\
  \"operationId\": \"string\",\
  \"message\": \"string\",\
  \"author\": {\
    \"name\": \"string\",\
    \"email\": \"user@example.com\"\
  }\
}",
)
```

### Response 200 default

```json
{
  "$schema": "http://example.com",
  "data": {
    "workspace": {
      "id": "string",
      "spaceId": "string",
      "repositoryId": "string",
      "targetBranch": "string",
      "name": "string",
      "revision": 9007199254740991,
      "state": "initializing",
      "baseCommitSha": "string",
      "indexCommitSha": "string",
      "workingCommitSha": "string",
      "headCommitSha": "string",
      "originalUploadVersionId": "string",
      "hasStagedChanges": true,
      "hasUnstagedChanges": true,
      "hasPendingChanges": true,
      "needsSync": true,
      "pendingOperationId": "string",
      "autoDeploy": true,
      "createdAt": "string",
      "updatedAt": "string"
    },
    "commit": {
      "sourceCommitSha": "string",
      "parentSourceCommitSha": "string",
      "message": "string",
      "autoDeploy": true
    },
    "conflicts": {
      "phase": "staged",
      "labels": {
        "ours": "string",
        "theirs": "string"
      },
      "files": [
        {
          "path": "string",
          "result": "string",
          "base": {
            "sourceCommitSha": "string",
            "content": "string",
            "exists": true,
            "binary": true,
            "truncated": true
          },
          "ours": {
            "sourceCommitSha": "string",
            "content": "string",
            "exists": true,
            "binary": true,
            "truncated": true
          },
          "theirs": {
            "sourceCommitSha": "string",
            "content": "string",
            "exists": true,
            "binary": true,
            "truncated": true
          }
        }
      ]
    }
  }
}
```

### Error Response

```json
{
  "$schema": "http://example.com",
  "type": "string",
  "title": "string",
  "status": -9007199254740991,
  "detail": "string",
  "code": "string",
  "pointer": "string",
  "details": {
    "property1": null,
    "property2": null
  },
  "suggestions": [
    "string"
  ],
  "next": [
    "string"
  ],
  "requestId": "string"
}
```
