# Write files of a website

> Up to 50 files written into the folder of a website of a web hosting package, all or none.

- Effect: Write - Changes the account. Agents ask first.
- Idempotent: no
- Stability: beta
- MCP tool: `manitu_webhosting_web_file_write` on https://mcp.manitu.de/mcp
- REST: `POST https://api.manitu.de/v1/webhosting/web/file/write`
- Needs: `service_webhosting`
- Page: /reference/webhosting/web/file/write/

**Changes the account. Agents say what will happen and wait for an explicit yes before calling it.**

## MCP tool

`manitu_webhosting_web_file_write`

### Description for the model

Writes files into the folder of a website of a web hosting package of the manitu customer account this connection works in, by site_id and fqdn: file_list with up to 50 files, 512 KB together - all written, or none. Before the first write in a conversation, call manitu_webhosting_web_file_guide_get and follow it. mode create (default) for a new file; mode replace for an existing one, with if_match = its sha256 from manitu_webhosting_web_file_get or manitu_webhosting_web_file_list - never guess it; a file changed since is refused (if_match_failed), read it again. mode overwrite replaces whatever is there without a check and cannot be undone - only when the customer explicitly asks to replace the existing files. Folders that are not there are created (create_parents, default true). PHP, .htaccess and .user.ini may be written (is_active_content) - they run on the website. dry_run checks everything and writes nothing. Refused with E2002 per item (/file_list/<n>/path: exists, not_found, path_invalid ...) - then nothing is written - or a conflict (quota_almost_exceeded, quota_exceeded, permission_denied, limit_reached, not_configurable). Tell the customer which files of which website change, and ask for an explicit yes first.

### Arguments

- `site_id` (integer | string, required) - The site_id from manitu_webhosting_list - never guess one. (pattern `"^[1-9][0-9]*$"`; minimum `1`)
- `fqdn` (string, required) - The website from manitu_webhosting_web_vhost_list, e.g. www.example.de - the paths are relative to its folder. Never guess one. (minLength `3`; maxLength `253`)
- `file_list` (array of object, required) - The files. (minItems `1`; maxItems `50`)
  - `file_list[].path` (string, required) - The file. Below the website's folder, as the answers write it: a file "/index.php" or "/css/style.css", a folder "/css/" ("/" the website's folder). Names: letters, digits and . _ - + = @, no leading dot - except .htaccess, .user.ini and the folder .well-known. (minLength `1`; maxLength `1024`)
  - `file_list[].content` (string, required) - The whole content - as text, or base64 with encoding base64.
  - `file_list[].encoding` (string) - text (default; UTF-8, written as given) or base64 (any bytes, e.g. an image). (one of `"text"`, `"base64"`)
  - `file_list[].mode` (string) - create (default): a new file; replace: an existing one, with if_match; overwrite: created or replaced without a check - only when the customer asks for it. (one of `"create"`, `"replace"`, `"overwrite"`)
  - `file_list[].if_match` (string) - For replace (only): the sha256 of the file as it was read. (pattern `"^[0-9a-f]{64}$"`)
- `create_parents` (boolean) - Create folders that are not there (default true).
- `dry_run` (boolean) - Check everything, write nothing (default false).

### Example

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "manitu_webhosting_web_file_write",
    "arguments": {
      "site_id": 12345,
      "fqdn": "example.com",
      "file_list": [
        {
          "path": "/web",
          "content": "string"
        }
      ]
    }
  }
}
```

## REST

`POST https://api.manitu.de/v1/webhosting/web/file/write`

### Authentication

One of `X-API-Key`, `Authorization: Bearer …` - never more than one in a request.

### Request body

JSON; unknown fields are refused.

- `site_id` (integer | string, required) - The site_id from manitu_webhosting_list - never guess one. (pattern `"^[1-9][0-9]*$"`; minimum `1`)
- `fqdn` (string, required) - The website from manitu_webhosting_web_vhost_list, e.g. www.example.de - the paths are relative to its folder. Never guess one. (minLength `3`; maxLength `253`)
- `file_list` (array of object, required) - The files. (minItems `1`; maxItems `50`)
  - `file_list[].path` (string, required) - The file. Below the website's folder, as the answers write it: a file "/index.php" or "/css/style.css", a folder "/css/" ("/" the website's folder). Names: letters, digits and . _ - + = @, no leading dot - except .htaccess, .user.ini and the folder .well-known. (minLength `1`; maxLength `1024`)
  - `file_list[].content` (string, required) - The whole content - as text, or base64 with encoding base64.
  - `file_list[].encoding` (string) - text (default; UTF-8, written as given) or base64 (any bytes, e.g. an image). (one of `"text"`, `"base64"`)
  - `file_list[].mode` (string) - create (default): a new file; replace: an existing one, with if_match; overwrite: created or replaced without a check - only when the customer asks for it. (one of `"create"`, `"replace"`, `"overwrite"`)
  - `file_list[].if_match` (string) - For replace (only): the sha256 of the file as it was read. (pattern `"^[0-9a-f]{64}$"`)
- `create_parents` (boolean) - Create folders that are not there (default true).
- `dry_run` (boolean) - Check everything, write nothing (default false).

### Response

In `data`; the rest of the body as on every call.

- `fqdn` (string, required)
- `dry_run` (boolean, required)
- `is_complete` (boolean, required) - Every file was written (false for a dry run) - false otherwise: see status.
- `result_list` (array of object, required)
  - `result_list[].path` (string, required)
  - `result_list[].status` (string, required) - would_*: a dry run. (one of `"created"`, `"replaced"`, `"would_create"`, `"would_replace"`, `"not_written"`)
  - `result_list[].sha256_before` (string | null, required) - Of the file replaced - null for a new one, or one overwrite could not read.
  - `result_list[].sha256_after` (string, required) - Of the content written - if_match for the next replace.
  - `result_list[].size` (integer, required) - Bytes.
  - `result_list[].is_active_content` (boolean, required) - Run by the web server (PHP, CGI) or changing how it runs (.htaccess, .user.ini).

### Statuses

- `200` Success.
- `400` The request does not match the declared input schema.
- `401` No credential was presented, or it was not recognised.
- `403` The credential is not permitted to use this operation.
- `500` The server failed. Nothing about the request was wrong. Whether a change took effect is not known - check before trying it again.
- `503` The channel this operation forwards through is unavailable.

### Example

```sh
curl -X POST 'https://api.manitu.de/v1/webhosting/web/file/write' \
  -H 'X-API-Key: $API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"site_id":12345,"fqdn":"example.com","file_list":[{"path":"/web","content":"string"}]}'
```

## Example result

```json
{
  "fqdn": "example.com",
  "dry_run": true,
  "is_complete": true,
  "result_list": [
    {
      "path": "/web",
      "status": "created",
      "sha256_before": "string",
      "sha256_after": "string",
      "size": 1,
      "is_active_content": true
    }
  ]
}
```
