63 lines
1.8 KiB
Markdown
63 lines
1.8 KiB
Markdown
# PocketBase Admin API (v0.39.1)
|
|
|
|
PocketBase runs in Docker at `127.0.0.1:8091`. Admin panel: http://127.0.0.1:8091/_/
|
|
|
|
## Superuser Management
|
|
|
|
Create via CLI:
|
|
```bash
|
|
docker exec pocketbase /usr/local/bin/pocketbase superuser create <email> <password> --dir /pb_data
|
|
```
|
|
|
|
## API Authentication
|
|
|
|
Superuser auth endpoint (v0.39.x):
|
|
```
|
|
POST /api/collections/_superusers/auth-with-password
|
|
{"identity": "admin@shop.com", "password": "admin123"}
|
|
→ returns {token, record}
|
|
```
|
|
|
|
Note: `/api/admins/auth-with-password` returns 404 in v0.39.1. Use the collections path above.
|
|
|
|
## Creating Collections
|
|
|
|
POST `/api/collections` with:
|
|
- `name`, `type: "base"`
|
|
- `fields` array (NOT `schema` — that's ignored)
|
|
- API rules: `listRule`, `viewRule`, `createRule`, `updateRule`, `deleteRule`
|
|
|
|
**Important**: Local collections use `text` type for userId (NOT `relation`). The existing `services`, `quotes`, etc. collections all store userId as plain text strings, not relation fields.
|
|
|
|
Example:
|
|
```python
|
|
{
|
|
"name": "service_advisors",
|
|
"type": "base",
|
|
"listRule": "userId = '{userid}'",
|
|
"viewRule": "userId = '{userid}'",
|
|
"createRule": "@request.auth.id != ''",
|
|
"updateRule": "userId = '{userid}'",
|
|
"deleteRule": "userId = '{userid}'",
|
|
"fields": [
|
|
{"name": "name", "type": "text", "required": True},
|
|
{"name": "userId", "type": "text", "required": True},
|
|
],
|
|
}
|
|
```
|
|
|
|
## Updating Collection Rules
|
|
|
|
PATCH `/api/collections/<collection_name>` with just the rule fields:
|
|
```python
|
|
{"listRule": "userId = '{userid}'", "viewRule": "userId = '{userid}'", ...}
|
|
```
|
|
|
|
## Deleting a Collection
|
|
|
|
DELETE `/api/collections/<collection_id>` — use the ID from GET `/api/collections/<name>`, not the name.
|
|
|
|
## Data Directory
|
|
|
|
`/pb_data` inside the container. Contains `data.db`, `auxiliary.db`, `storage/`.
|