# editSpaceTextLines

Reorganize or rewrite part of a text file by line number (from getSpaceTextLines), as one new version like a save: each edit replaces a range `startLine`-`endLine` with `text` (empty deletes it), MOVES the range before `beforeLine` (no `text`: its characters are kept exactly, nothing re-sent), or with no range inserts `text` before `beforeLine`. Every number is the read version's, the edits apply together, and every line no edit names stays exactly as it was. Overlapping ranges, a target inside a range being changed, and a stale `baseVersionId` are refused. Use it to put a long file into sections, reorder it, or fix lines without re-sending the whole file.

- Call: `POST https://server.goliathdata.com/api/v1/call` with `{ "operationId": "editSpaceTextLines", "variables": {...} }`
- Scope: `WRITE`
- Type: mutation
- Idempotency: honors `Idempotency-Key` (24 h)
- Rate-limited: no

## Variables

- `input`: `EditSpaceTextLinesInput!` (required)
  - `itemId`: `ID!` (required)
  - `baseVersionId`: `ID!` (required). The versionId the line numbers were read from; refused if someone saved since.
  - `edits`: `[SpaceTextLineEdit!]!` (required). Applied together as one new version; ranges may not overlap.
    - `startLine`: `Int`. First line of the range to replace, delete or move.
    - `endLine`: `Int`. Last line of that range (inclusive).
    - `text`: `String`. The range's new lines ("" deletes it), or the lines to insert.
    - `beforeLine`: `Int`. Where a moved range or inserted lines go: before this line (the file's line count + 1 = the end).

## Response (data, an example)

```json
{
  "spacesMutation": {
    "editTextLines": {
      "id": "<ID>",
      "spaceId": "<ID>",
      "spaceName": "…",
      "parentId": "<ID>",
      "kind": "FOLDER",
      "name": "…",
      "description": "…",
      "fileType": "…",
      "sizeBytes": 0,
      "accessMode": "INHERIT",
      "systemLocked": true,
      "viewerRole": "VIEWER",
      "abilities": {
        "addChildren": true,
        "edit": true,
        "move": true,
        "trash": true,
        "share": true
      },
      "owner": {
        "id": "<ID>",
        "name": "…"
      },
      "createdBy": {
        "kind": "PERSON",
        "label": "…"
      },
      "childCount": 0,
      "shareCount": 0,
      "currentVersion": {
        "id": "<ID>",
        "versionNumber": 0
      },
      "path": [
        {
          "id": "<ID>",
          "name": "…"
        }
      ],
      "updatedAt": "2026-01-01T00:00:00.000Z",
      "trashedAt": "2026-01-01T00:00:00.000Z"
    }
  }
}
```

## Example

```bash
curl https://server.goliathdata.com/api/v1/call \
  -H "Authorization: Bearer $GOLIATH_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "operationId": "editSpaceTextLines",
    "variables": {
      "input": {
        "itemId": "<itemId>",
        "baseVersionId": "<baseVersionId>",
        "edits": [
          {}
        ]
      }
    }
  }'
```
