# POST /protected-folders

First published 4 Nov 2026 (release 0.2.24) · Unchanged since publication

UrbeStack release 0.2.35 API operation in the files group.

Protect a folder with HTTP Basic authentication

- Who may call it: administrator, reseller, customer
- Token scope, any of: files, all
- Answers: 201 Created

The target account defaults to the caller. Administrators and resellers can use user to select a customer they manage. The API returns 400 if the selected account is an administrator.

Use a path that starts with /, which represents the customer's home. Choose an existing directory served by one of the account's sites. UrbeStack refuses symbolic links in any component. The API returns 400 for / itself, a missing path, a path that lacks the leading / or contains a control character or a .. component, a path over 4096 characters, or a component over 255 characters. It also returns 400 if the normalized path exceeds 1024 bytes or contains any of these characters, ", \, *, ?, [, or ].

Every site whose document root is the folder or contains it requires HTTP Basic authentication for the folder and its contents. Apache denies access until you add a folder user. When a directory has no index page, list_files defaults to true, so Apache lists its contents for authenticated visitors. Set list_files to false to make Apache return 403 Forbidden in that case. A site that uses the folder as its document root applies its own directory listing setting.

UrbeStack regenerates the affected virtual host configurations and reloads Apache immediately. The API returns 201 with the protected folder in folder.

## As a command

- [urbestack-protected-folder-add](https://urbestack.com/docs/commands/urbestack-protected-folder-add.md): Protects a customer's folder with HTTP Basic authentication.

## Request body

JSON, the type [ProtectedFolderCreate](https://urbestack.com/docs/api/types/ProtectedFolderCreate.md).

- `path` (HomePath, required): Path to an existing directory at or below a site's document root. The customer's home directory and the characters double quote, backslash, asterisk, question mark, and square brackets are prohibited.
- `list_files` (boolean): Whether authenticated visitors see a file listing when the folder has no index page.
- `user` (Username): Username of the customer who owns the folder, for requests by administrators or resellers.

## Example

Set $API to the base URL and $TOKEN to the token, as the [API overview](https://urbestack.com/docs/api.md) shows.

```
curl -sS -X POST "$API/protected-folders" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "list_files": true,
    "path": "public_html/index.php",
    "user": "alice"
  }'
```

Response, 201 Created:

```
{
  "folder": {
    "created_at": "2026-09-09T10:15:00Z",
    "exists": true,
    "id": 1,
    "list_files": true,
    "path": "public_html/index.php",
    "sites": [
      {
        "domain": "example.com",
        "url": "text"
      }
    ],
    "users": [
      {
        "created_at": "2026-09-09T10:15:00Z",
        "enabled": true,
        "ended": true,
        "expires_at": "2026-09-16T10:15:00Z",
        "updated_at": "text",
        "username": "text"
      }
    ]
  }
}
```

## Errors

- 400: --path is required
- 400: --user is required
- 400: <name> is an administrator: administrators have no home, so no folders to protect
- 400: <path> is a link to another location. Choose a folder, not a link.
- 400: <path> isn't a folder.
- 400: <path> isn't part of a website, so it can't be protected here.
- 400: <what> climbs out of the home with ..
- 400: <what> has a name over 255 characters
- 400: <what> holds a control character
- 400: <what> is required
- 400: <what> is too long
- 400: <what> must start with /, which is the home
- 400: Invalid username: 2 to 32 lowercase letters, digits or underscores, starting with a letter
- 400: The path is too long
- 400: Username '<value>' is reserved
- 400: Your home folder isn't a website. Choose a folder inside a website.
- 401: Authentication required
- 404: Folder <path> wasn't found in your files.
- 404: User '<user>' not found
- 409: <path> is already protected.
