---
title: "Create or update a source file"
method: PUT
path: "/websiteSourceCode/files"
tags: ["Source code"]
---

# Create or update a source file

`PUT /websiteSourceCode/files`

## Request

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

Creates or replaces one head file. Pages, components, and modules require `name`; singleton types take only `type`. Takes the edit lease when no `leaseToken` is sent and returns `changed: false` for identical content.

## Request body

- object
  - `websiteId` string, required
  - `file` union, required
    - object
      - `type` 'page', required
      - `name` string, required
    - object
      - `type` 'component', required
      - `name` string, required
    - object
      - `type` 'module', required
      - `name` string, required
    - object
      - `type` 'server_function', required
      - `name` string, required
    - object
      - `type` 'global_css' | 'not_found' | 'website_config' | 'custom_head_start' | 'custom_head_end' | 'custom_body_start' | 'custom_body_end', required
  - `content` string, required
  - `leaseToken` string: Omit to have Cactal take the edit lease for you; pass a token from websiteSourceCode.lease.acquire to take over from another editor.

## Response `200`

The new head version after the edit.

- object
  - `version` integer, required: Head version after the edit: the previous head plus one, or the unchanged head when `changed` is `false`.
  - `changed` boolean, required: `false` when the edit was a no-op and no new version was created.

## 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.
- `409`: The request conflicts with the current state of the resource.
- `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)
