---
title: "Create a password-protected directory using HTTP Basic Auth on a Hosted EZ site"
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.hostedez.com/llms.txt
> Use this file to discover all available pages before exploring further.

Path: Hosted EZ REST API

`POST /v1/sites/{siteId}/protected-dirs`

## Authentication

- `sessionCookie`, apiKey, in cookie

## Path parameters

- `createSiteProtectedDir.path.siteId` (string, required) — Site slug (sit_...) or UUID.

## Header parameters

- `createSiteProtectedDir.header.Idempotency-Key` (string, optional) — Optional idempotency key (1 to 255 printable ASCII characters) scoped to caller and route.
  - minLength 1; maxLength 255

## Request body

_Required._

- `createSiteProtectedDir.password` (string, required) — Plaintext password (8 to 72 bytes); hashed with bcrypt before storage and never returned.
  - minLength 8; maxLength 72
- `createSiteProtectedDir.path` (string, required)
  - minLength 1; maxLength 512
- `createSiteProtectedDir.realm` (string, required)
  - minLength 1; maxLength 64
- `createSiteProtectedDir.username` (string, required)
  - pattern `^[A-Za-z0-9._-]{1,64}$`
- `createSiteProtectedDir.enabled` (boolean, optional)
  - default `true`

## Example request

```json
{
  "enabled": true,
  "password": "stringst",
  "path": "string",
  "realm": "string",
  "username": "string"
}
```

## Code samples

### cURL

```curl
curl --request POST \
  --url https://api.hostedez.com/v1/sites/string/protected-dirs \
  --header 'Content-Type: application/json' \
  --header '__Secure-better-auth.session_token: <value>' \
  --data '
{
  "enabled": true,
  "password": "stringst",
  "path": "string",
  "realm": "string",
  "username": "string"
}
'
```

### TypeScript

```typescript
const url = 'https://api.hostedez.com/v1/sites/string/protected-dirs';
const options = {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    '__Secure-better-auth.session_token': '<value>'
  },
  body: JSON.stringify({
    enabled: true,
    password: 'stringst',
    path: 'string',
    realm: 'string',
    username: 'string'
  })
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://api.hostedez.com/v1/sites/string/protected-dirs"

payload = {
    "enabled": True,
    "password": "stringst",
    "path": "string",
    "realm": "string",
    "username": "string"
}
headers = {
    "Content-Type": "application/json",
    "__Secure-better-auth.session_token": "<value>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 201

Protected directory created

#### Example

```json
{
  "directory": {
    "createdAt": "2019-08-24T14:15:22Z",
    "enabled": true,
    "id": "string",
    "path": "string",
    "realm": "string",
    "siteId": "string",
    "updatedAt": "2019-08-24T14:15:22Z",
    "username": "string"
  }
}
```

- `createSiteProtectedDir.response.201.directory` (object, required) — Password-protected directory rule. Passwords are stored as bcrypt hashes and are never returned by the API.
  - `createSiteProtectedDir.response.201.directory.createdAt` (string, required)
    - format `date-time`
  - `createSiteProtectedDir.response.201.directory.enabled` (boolean, required)
  - `createSiteProtectedDir.response.201.directory.id` (string, required) — Prefixed protected directory ID (pdr_...).
  - `createSiteProtectedDir.response.201.directory.path` (string, required) — Protected URL path starting with '/'.
  - `createSiteProtectedDir.response.201.directory.realm` (string, required) — HTTP Basic Auth realm prompt shown in browsers.
  - `createSiteProtectedDir.response.201.directory.siteId` (string, required) — Hosted EZ site slug (sit_...).
  - `createSiteProtectedDir.response.201.directory.updatedAt` (string, required)
    - format `date-time`
  - `createSiteProtectedDir.response.201.directory.username` (string, required)

### 400

Invalid protected directory payload

#### Example

```json
{
  "error": {
    "code": "string",
    "issues": [
      {
        "message": "string",
        "path": "string"
      }
    ],
    "message": "string"
  }
}
```

- `createSiteProtectedDir.response.400.error` (object, required)
  - `createSiteProtectedDir.response.400.error.code` (string, required)
  - `createSiteProtectedDir.response.400.error.message` (string, required)
  - `createSiteProtectedDir.response.400.error.issues` (array<object>, optional)
    - `createSiteProtectedDir.response.400.error.issues.message` (string, required)
    - `createSiteProtectedDir.response.400.error.issues.path` (string, required)

### 401

Unauthenticated

#### Example

```json
{
  "error": {
    "code": "string",
    "issues": [
      {
        "message": "string",
        "path": "string"
      }
    ],
    "message": "string"
  }
}
```

- `createSiteProtectedDir.response.401.error` (object, required)
  - `createSiteProtectedDir.response.401.error.code` (string, required)
  - `createSiteProtectedDir.response.401.error.message` (string, required)
  - `createSiteProtectedDir.response.401.error.issues` (array<object>, optional)
    - `createSiteProtectedDir.response.401.error.issues.message` (string, required)
    - `createSiteProtectedDir.response.401.error.issues.path` (string, required)

### 403

Forbidden origin

#### Example

```json
{
  "error": {
    "code": "string",
    "issues": [
      {
        "message": "string",
        "path": "string"
      }
    ],
    "message": "string"
  }
}
```

- `createSiteProtectedDir.response.403.error` (object, required)
  - `createSiteProtectedDir.response.403.error.code` (string, required)
  - `createSiteProtectedDir.response.403.error.message` (string, required)
  - `createSiteProtectedDir.response.403.error.issues` (array<object>, optional)
    - `createSiteProtectedDir.response.403.error.issues.message` (string, required)
    - `createSiteProtectedDir.response.403.error.issues.path` (string, required)

### 404

Site not found

#### Example

```json
{
  "error": {
    "code": "string",
    "issues": [
      {
        "message": "string",
        "path": "string"
      }
    ],
    "message": "string"
  }
}
```

- `createSiteProtectedDir.response.404.error` (object, required)
  - `createSiteProtectedDir.response.404.error.code` (string, required)
  - `createSiteProtectedDir.response.404.error.message` (string, required)
  - `createSiteProtectedDir.response.404.error.issues` (array<object>, optional)
    - `createSiteProtectedDir.response.404.error.issues.message` (string, required)
    - `createSiteProtectedDir.response.404.error.issues.path` (string, required)

### 409

Duplicate protected path, per-site limit reached, site suspended/deleting, or idempotency conflict

#### Example

```json
{
  "error": {
    "code": "string",
    "issues": [
      {
        "message": "string",
        "path": "string"
      }
    ],
    "message": "string"
  }
}
```

- `createSiteProtectedDir.response.409.error` (object, required)
  - `createSiteProtectedDir.response.409.error.code` (string, required)
  - `createSiteProtectedDir.response.409.error.message` (string, required)
  - `createSiteProtectedDir.response.409.error.issues` (array<object>, optional)
    - `createSiteProtectedDir.response.409.error.issues.message` (string, required)
    - `createSiteProtectedDir.response.409.error.issues.path` (string, required)


Source: https://docs.hostedez.com/api/createSiteProtectedDir/index.md
