# POST /protected-folders/{id}/users

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

UrbeStack release 0.2.35 API operation in the files group.

Add a user to a protected folder

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

The username must be unique within the folder. It must be 1 to 64 characters, begin with an ASCII letter or digit, and contain only ASCII letters, digits, dots, underscores, hyphens, @, and +. The password must contain 8 to 128 printable ASCII characters. UrbeStack hashes it the same way it hashes a system password.

The user starts enabled. Omit expires_at or pass null or an empty string to leave access open-ended. To set an end time, pass a valid future UTC timestamp in the format 2026-11-04T09:30:00Z. Apache uses its own clock to end access at that minute. The user stays listed as ended until you set a new end time, clear it, or remove the user.

UrbeStack reloads Apache immediately and returns 201 with the updated protected folder in the folder field.

The caller must be signed in, have permission to act on the folder owner's account, and use a token with the files scope. The API returns 400 for an invalid folder ID, username format, password, or end time, and 404 if the protected folder does not exist.

## As a command

- [urbestack-protected-user-add](https://urbestack.com/docs/commands/urbestack-protected-user-add.md): Adds a user to a customer's password-protected folder.

## Parameters

- `id` (path, integer, 1 or more, required): The protected folder ID returned by the listing.

## Request body

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

- `password` (string, up to 128 characters, required): Password of 8 to 128 printable ASCII characters. Browsers can encode other characters differently in Basic authentication.
- `username` (ProtectedUsername, required): A Basic authentication username must be 1 to 64 characters long and start with a letter or digit. Allowed characters are letters, digits, dots, underscores, hyphens, @, and +.
- `expires_at` (string, matching ^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$ or null): Future UTC time, such as 2026-11-04T09:30:00Z, at which Apache stops granting the user access. Omit this field to grant access with no expiration.

## 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/1/users" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "expires_at": "2026-09-16T10:15:00Z",
    "password": "Sup3r-Secret-Passphrase",
    "username": "text"
  }'
```

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: --<_> is required
- 400: --password-stdin is required: the password comes on standard input
- 400: --user is required
- 400: Invalid password: 8 to 128 printable characters
- 400: Invalid username: 2 to 32 lowercase letters, digits or underscores, starting with a letter
- 400: The access end date (<value>) is in the past.
- 400: The folder id is a number
- 400: The password must be 8\x{2013}128 characters using letters, numbers, or punctuation (no accented characters).
- 400: The username must be 1\x{2013}64 characters, start with a letter or number, and contain only letters, numbers, dots, underscores, hyphens, @ or +.
- 400: Username '<value>' is reserved
- 400: expires_at has passed already: <t>
- 400: expires_at is a UTC time spelled as 2026-11-04T09:30:00Z
- 400: expires_at is not a day the calendar has: <t>
- 401: Authentication required
- 404: No protected folder <id>
- 404: User '<user>' not found
- 409: <name> is already a user of <f.path>
