---
title: "Read source files"
method: POST
path: "/websiteSourceCode/files/read"
tags: ["Source code"]
---

# Read source files

`POST /websiteSourceCode/files/read`

## Request

- Base URL: `https://api.cactal.ai/v1`
- URL: `https://api.cactal.ai/v1/websiteSourceCode/files/read`
- Auth: HTTP bearer

Reads up to 50 files by name from head, published, or an explicit version. A single-file read supports line and character ranges; continue truncated reads with `nextStartCharacter` and the resolved `version`.

## Request body

- object
  - `websiteId` string, required
  - `target` 'head' | 'published': Version alias to read: `head` (default) or `published`.
  - `version` integer: Explicit source version. Takes precedence over `target`.
  - `names` string[], required: File names to read (up to 50). Singleton files are addressed by their type name, for example `global_css`.
  - `startLine` integer: First line to return (1-based, inclusive). Only valid when reading a single file.
  - `endLine` integer: Last line to return (1-based, inclusive). Only valid when reading a single file.
  - `startCharacter` integer: First character to return from the selected line range (1-based, inclusive). Only valid when reading a single file.
  - `endCharacter` integer: Last character to return from the selected line range (1-based, inclusive). Only valid when reading a single file.

## Response `200`

The requested files with their contents.

- object
  - `websiteId` string, required: Id of the website.
  - `version` integer, required: Source version that was read. Pass it as `version` when continuing truncated content.
  - `files` object[], required: The requested files in request order.
    - `type` 'page' | 'component' | 'module' | 'server_function' | 'global_css' | 'not_found' | 'website_config' | 'custom_head_start' | 'custom_head_end' | 'custom_body_start' | 'custom_body_end', required: File type.
    - `name` string, required: File name.
    - `content` string, required: Source text: the whole file, or the requested line range.
    - `totalLines` integer, required: Total number of lines in the full file.
    - `truncated` boolean: `true` when content was cut at the size cap. Continue with `nextStartCharacter` or request a narrower line range.
    - `nextStartCharacter` integer: Pass as `startCharacter` with the same line range and the response `version` to continue truncated content.

## Other responses

- `400`: Validation failed. The response `message` names the first invalid field.
- `401`: Missing, invalid, expired, or revoked API key.
- `403`: The authenticated principal lacks the required capability.
- `404`: The resource does not exist or is outside the principal’s access scope.
- `429`: Rate limit exceeded. Retry after the number of seconds in the `Retry-After` header.

---

[API](https://skmtc.dev/cactal/apis/cactal-api.md) · [All operations](https://skmtc.dev/cactal/apis/cactal-api/llms.txt) · [OpenAPI document](https://skmtc.dev/cactal/apis/cactal-api/revisions/9cd0fb5eacdd?raw)
