# Write file

```http
PUT /projects/{project_reference}/files/{file_path}
```

Create a file or replace its content. Requires project.files.write.

## Parameters

| Name                | In    | Required | Description |
| ------------------- | ----- | -------- | ----------- |
| `project_reference` | path  | Yes      |             |
| `file_path`         | path  | Yes      |             |
| `ref`               | query |          |             |
| `branch`            | query |          |             |
| `branch_id`         | query |          |             |

## Request body

| Field                 | Type    | Required | Description                                                                                                                           |
| --------------------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `content`             | string  | Yes      | Replacement textual content in main or the selected branch, stored as a new immutable version. Source-file MIME type is not writable. |
| `expected_checksum`   | string  |          | Expected current checksum when updating an existing file; ignored on creation. Omission disables this guard.                          |
| `expected_version_id` | string  |          | Expected current version ID when updating an existing file; ignored on creation. Omission disables this guard.                        |
| `metadata`            | object  |          | Optional durable file-version metadata for source provenance; service-owned visibility keys are rejected.                             |
| `expected_absent`     | boolean |          | True requires absence atomically when creating; an existing file returns 409. False or omission retains upsert behavior.              |

## Responses

| Status | Description               |
| ------ | ------------------------- |
| 200    | File updated successfully |
| 201    | File created successfully |
| 400    | Bad request               |
| 401    | Unauthorized              |
| 403    | Forbidden                 |
| 404    | Not found                 |
| 409    | Conflict                  |
| 500    | Server error              |
