# Create a commit from a diff

Save a unified diff as one Git commit in a hosted repository. Send expectedHeadSha to reject stale writes. A commit does not confirm deployment.

## Endpoint

**POST** `/v1/spaces/{spaceId}/source/commits/diff`

## 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`

## Path parameters

- `spaceId` string required

## Request body

**required** `application/json`

### `author` object
Git author. Omit it to use the registered profile of the authenticated user or machine credential creator. Attribution does not change permissions.

#### Properties
- `name` string required (min length 1)
- `email` string <email> required (must match email format regex)
- `baseBranch` string (min length 1)
- `commitMessage` string required (min length 1)

### `committer` object
#### Properties
- `name` string required (min length 1)
- `email` string <email> required (must match email format regex)
- `connectionType` string required (Allowed: `connected`, `hosted`)
- `diff` string required (min length 1, max length 4194304)
- `ephemeral` boolean
- `ephemeralBase` boolean
- `expectedHeadSha` string (min length 1)
- `targetBranch` string required (min length 1)

## Responses

### 201 Response
#### Properties
- `$schema` string <uri>
- `data` object required

##### Properties of `data`
- `repositoryConnection` object required
  - `id` string required
  - `spaceId` string required
  - `provider` string required (Allowed: `github`, `gitlab`, `bitbucket`, `generic`)
  - `connectionType` string required (Allowed: `connected`, `hosted`)
  - `repositoryId` string | any required
  - `installationId` string | any required (default: null)
  - `cloneUrlConfigured` boolean required (default: false)
  - `upstreamUrlConfigured` boolean required (default: false)
  - `repositoryName` string required
  - `repositoryFullName` string required
  - `defaultBranch` string required
  - `productionBranch` string required
  - `credentialConfigured` boolean required
  - `autoDeployProduction` boolean required
  - `autoDeployPreviews` boolean required
  - `buildSettings` object required
    - `rootDirectory` string | any required (default: null)
    - `installDirectory` string | any required (default: null)
    - `installCommand` string | any required (default: null)
    - `buildCommand` string | any required (default: null)
    - `outputDirectory` string | any required (default: null)
    - `ignoredBuildCommand` string | any required (default: null)
    - `frameworkPreset` string | any required (default: null)
    - `platformPreset` string | any required (default: null)
    - `allowUnsupportedPlatformFeatures` boolean required (default: false)
    - `timeoutSeconds` integer required (min 60, max 7200, default: 900)
  - `syncStatus` string required (Allowed: `idle`, `syncing`, `ready`, `failed`)
  - `providerAccessStatus` string required (Allowed: `active`, `suspended`, `revoked`, `reauthorization_required`, default: "active")
  - `providerAccessError` string | any required (default: null)
  - `lastSyncedAt` string <date-time> | any required
  - `lastSyncError` string | any required
  - `syncRunId` string | any required
  - `connectedUserId` string | any required
  - `createdAt` string <date-time> required
  - `updatedAt` string <date-time> required
- `repositoryId` string required
- `commitSha` string required
- `treeSha` string required
- `targetBranch` string required
- `packBytes` integer required (min 0, max 9007199254740991)
- `blobCount` integer required (min 0, max 9007199254740991)
- `refUpdate` object required
  - `branch` string required
  - `oldSha` string required
  - `newSha` string required

### Error Response
#### Properties
- `$schema` string <uri>
- `type` string required
- `title` string required
- `status` integer required (min -9007199254740991, max 9007199254740991)
- `detail` string required
- `code` string required
- `pointer` string
- `details` object
- `suggestions` string[]
- `next` string[]
- `requestId` string required

## Example Requests

### cURL
```
curl -X POST "https://api.spacefast.com/v1/spaces/string/source/commits/diff" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "author": {
    "name": "string",
    "email": "user@example.com"
  },
  "baseBranch": "string",
  "commitMessage": "string",
  "committer": {
    "name": "string",
    "email": "user@example.com"
  },
  "connectionType": "connected",
  "diff": "string",
  "ephemeral": true,
  "ephemeralBase": true,
  "expectedHeadSha": "string",
  "targetBranch": "string"
}'
```

### JavaScript
```
const response = await fetch("https://api.spacefast.com/v1/spaces/string/source/commits/diff", {
  method: "POST",
  headers: {
    "Authorization": "Bearer YOUR_TOKEN",
    "Content-Type": "application/json"
  },
  body: "{\n  \"author\": {\n    \"name\": \"string\",\n    \"email\": \"user@example.com\"\n  },\n  \"baseBranch\": \"string\",\n  \"commitMessage\": \"string\",\n  \"committer\": {\n    \"name\": \"string\",\n    \"email\": \"user@example.com\"\n  },\n  \"connectionType\": \"connected\",\n  \"diff\": \"string\",\n  \"ephemeral\": true,\n  \"ephemeralBase\": true,\n  \"expectedHeadSha\": \"string\",\n  \"targetBranch\": \"string\"\n}";
});
```

### Python
```
import requests

response = requests.post(
    "https://api.spacefast.com/v1/spaces/string/source/commits/diff",
    headers={
        "Authorization": "Bearer YOUR_TOKEN",
        "Content-Type": "application/json"
    },
    data="{\n  \"author\": {\n    \"name\": \"string\",\n    \"email\": \"user@example.com\"\n  },\n  \"baseBranch\": \"string\",\n  \"commitMessage\": \"string\",\n  \"committer\": {\n    \"name\": \"string\",\n    \"email\": \"user@example.com\"\n  },\n  \"connectionType\": \"connected\",\n  \"diff\": \"string\",\n  \"ephemeral\": true,\n  \"ephemeralBase\": true,\n  \"expectedHeadSha\": \"string\",\n  \"targetBranch\": \"string\"\n}",
)
```

## Example Response
### 201 Response
```json
{
  "$schema": "http://example.com",
  "data": {
    "repositoryConnection": {
      "id": "string",
      "spaceId": "string",
      "provider": "github",
      "connectionType": "connected",
      "repositoryId": "string",
      "installationId": null,
      "cloneUrlConfigured": false,
      "upstreamUrlConfigured": false,
      "repositoryName": "string",
      "repositoryFullName": "string",
      "defaultBranch": "string",
      "productionBranch": "string",
      "credentialConfigured": true,
      "autoDeployProduction": true,
      "autoDeployPreviews": true,
      "buildSettings": {
        "rootDirectory": null,
        "installDirectory": null,
        "installCommand": null,
        "buildCommand": null,
        "outputDirectory": null,
        "ignoredBuildCommand": null,
        "frameworkPreset": null,
        "platformPreset": null,
        "allowUnsupportedPlatformFeatures": false,
        "timeoutSeconds": 900
      },
      "syncStatus": "idle",
      "providerAccessStatus": "active",
      "providerAccessError": null,
      "lastSyncedAt": "2019-08-24T14:15:22Z",
      "lastSyncError": "string",
      "syncRunId": "string",
      "connectedUserId": "string",
      "createdAt": "2019-08-24T14:15:22Z",
      "updatedAt": "2019-08-24T14:15:22Z"
    },
    "repositoryId": "string",
    "commitSha": "string",
    "treeSha": "string",
    "targetBranch": "string",
    "packBytes": 9007199254740991,
    "blobCount": 9007199254740991,
    "refUpdate": {
      "branch": "string",
      "oldSha": "string",
      "newSha": "string"
    }
  }
}
```

### 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"
}
```
