Install any skill in seconds. Free to start, no credit card required.
Get Started Free →PocketBase Web API로 컬렉션(list/view/create/update/delete/truncate/import/scaffolds)을 안전하게 조회·수정·삭제한다
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-06 | ✗→✓ | ▲ Improved | 101% | 0% |
| case-07 | ✗→✓ | ▲ Improved | 130% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 237% | 0% |
| case-10 | ✗→✓ | ▲ Improved | 541% | 0% |
| case-13 | ✗→✓ | ▲ Improved | 164% | 0% |
PocketBase의 Collections(Web API) 엔드포인트를 사용해 컬렉션을 조회/생성/수정/삭제/비우기/일괄 가져오기/스캐폴드 조회한다.
다음 값이 필요하다.
PB_URL: PocketBase 서버의 base URL 예: http://127.0.0.1:8090 또는 https://pb.example.com
PB_ADMIN_EMAIL: superuser 이메일PB_ADMIN_PASSWORD: superuser 비밀번호PB_URL, PB_ADMIN_EMAIL, PB_ADMIN_PASSWORD)bashexport PB_URL="http://127.0.0.1:8090" export PB_ADMIN_EMAIL="admin@example.com" export PB_ADMIN_PASSWORD="your-password"
Collections API는 superuser 토큰이 필요하다. 토큰 발급은 _superusers auth 컬렉션의 auth-with-password를 사용한다.
${PB_URL}/api/collections/_superusers/auth-with-passwordjson { "identity": "admin@example.com", "password": "your-password" }
json { "token": "JWT_TOKEN_STRING", "record": { "...": "..." } }
Authorization: <token>Content-Type: application/json (JSON 바디를 보낼 때)PocketBase는 Authorization: Bearer <token> 형태가 아니라, Authorization: <token> 형태를 사용한다.
토큰 발급 bash 예시 (jq 사용)
bashPB_TOKEN="$( curl -sS -X POST "${PB_URL}/api/collections/_superusers/auth-with-password" \ -H "Content-Type: application/json" \ -d "{\"identity\":\"${PB_ADMIN_EMAIL}\",\"password\":\"${PB_ADMIN_PASSWORD}\"}" \ | jq -r .token )"
jq가 없다면 (python 사용)
bashPB_TOKEN="$( curl -sS -X POST "${PB_URL}/api/collections/_superusers/auth-with-password" \ -H "Content-Type: application/json" \ -d "{\"identity\":\"${PB_ADMIN_EMAIL}\",\"password\":\"${PB_ADMIN_PASSWORD}\"}" \ | python -c 'import sys,json; print(json.load(sys.stdin)["token"])' )"
${PB_URL}/api/...multipart/form-data로도 보낼 수 있으나, 기본은 JSON을 사용한다.collectionIdOrName에는 컬렉션 ID 또는 name을 넣을 수 있다.아래 작업은 되돌리기 어렵다. 사용자가 명시적으로 요청한 경우에만 실행한다.
DELETE /api/collections/{collectionIdOrName} (컬렉션 삭제)DELETE /api/collections/{collectionIdOrName}/truncate (레코드 전체 삭제)PUT /api/collections/import 중 deleteMissing=true (누락된 컬렉션/필드/데이터 삭제 가능)아래 모든 요청은 기본적으로 다음 헤더를 사용한다.
Authorization: <PB_TOKEN>
Content-Type: application/jsonGET /api/collectionspage (number, default 1)perPage (number, default 30)sort (string, 예: -created,id)filter (string, 예: (name~'abc' && created>'2022-01-01'))fields (string, 반환 필드 선택)skipTotal (boolean, total 계산 생략)PageResult<Collection>json { "page": 1, "perPage": 30, "totalItems": 123, "totalPages": 5, "items": [ { "id": "...", "name": "...", "type": "...", "fields": [ ... ] } ] }
bash curl -sS "${PB_URL}/api/collections?page=1&perPage=50&sort=-created" \ -H "Authorization: ${PB_TOKEN}"
GET /api/collections/{collectionIdOrName}Collectionjson { "id": "COLLECTION_ID", "name": "posts", "type": "base", "system": false, "listRule": null, "viewRule": null, "createRule": null, "updateRule": null, "deleteRule": null, "fields": [ { "name": "title", "type": "text" } ], "indexes": [] }
bash curl -sS "${PB_URL}/api/collections/posts" \ -H "Authorization: ${PB_TOKEN}"
/api/collectionsCollectionCreatejson{ "id": "optional_15_chars", "name": "required_unique_name", "type": "base | view | auth", // default: base "fields": [ /* Array<Field> */ ], // view는 viewQuery 기반 자동 채움(보통 생략 가능) "indexes": [ "CREATE INDEX ..." ], // view는 indexes 미지원 "system": false, "listRule": null, "viewRule": null, "createRule": null, "updateRule": null, "deleteRule": null, // type=view 일 때 필수 "viewQuery": "SELECT ...", // type=auth 일 때 주로 사용 "manageRule": null, "authRule": null, "authAlert": { "enabled": true, "emailTemplate": { "subject": "...", "body": "..." } }, "oauth2": { "enabled": false, "providers": [], "mappedFields": { "id": "", "name": "", "username": "", "avatarURL": "" } }, "passwordAuth": { "enabled": true, "identityFields": ["email"] }, "mfa": { "enabled": false, "duration": 1800, "rule": "" }, "otp": { "enabled": false, "duration": 180, "length": 8, "emailTemplate": { "subject": "...", "body": "..." } } }
Collectionbashcurl -sS -X POST "${PB_URL}/api/collections" \ -H "Authorization: ${PB_TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "name": "exampleBase", "type": "base", "fields": [ { "name": "title", "type": "text", "required": true, "min": 1 }, { "name": "status", "type": "bool" } ] }'
bashcurl -sS -X POST "${PB_URL}/api/collections" \ -H "Authorization: ${PB_TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "name": "exampleView", "type": "view", "listRule": "@request.auth.id != \"\"", "viewRule": null, "viewQuery": "SELECT id, name FROM posts" }'
jsoncurl -sS -X POST "${PB_URL}/api/collections" \ -H "Authorization: ${PB_TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "name": "exampleAuth", "type": "auth", "createRule": "id = @request.auth.id", "updateRule": "id = @request.auth.id", "deleteRule": "id = @request.auth.id", "fields": [ { "name": "name", "type": "text" } ], "passwordAuth": { "enabled": true, "identityFields": ["email"] } }'
PATCH /api/collections/{collectionIdOrName}CollectionUpdate (부분 업데이트)json{ "name": "required", "fields": [ /* Array<Field> */ ], "indexes": [ "CREATE INDEX ..." ], "system": false, "listRule": null, "viewRule": null, "createRule": null, "updateRule": null, "deleteRule": null, "viewQuery": "SELECT ...", "manageRule": null, "authRule": null, "authAlert": { "enabled": true, "emailTemplate": { "subject": "...", "body": "..." } }, "oauth2": { "enabled": false, "providers": [], "mappedFields": { "id": "", "name": "", "username": "", "avatarURL": "" } }, "passwordAuth": { "enabled": true, "identityFields": ["email"] }, "mfa": { "enabled": false, "duration": 1800, "rule": "" }, "otp": { "enabled": false, "duration": 180, "length": 8, "emailTemplate": { "subject": "...", "body": "..." } } }
Collectionbash curl -sS -X PATCH "${PB_URL}/api/collections/demo" \ -H "Authorization: ${PB_TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "name": "new_demo", "listRule": "created > \"2022-01-01 00:00:00\"" }'
DELETE /api/collections/{collectionIdOrName}nullbash curl -sS -X DELETE "${PB_URL}/api/collections/demo" \ -H "Authorization: ${PB_TOKEN}" \ -o /dev/null -w "%{http_code}\n"
DELETE /api/collections/{collectionIdOrName}/truncatenullbash curl -sS -X DELETE "${PB_URL}/api/collections/demo/truncate" \ -H "Authorization: ${PB_TOKEN}" \ -o /dev/null -w "%{http_code}\n"
PUT /api/collections/importjson { "collections": [ /* Array<Collection> */ ], "deleteMissing": false }
null> deleteMissing=true는 "import에 없는 기존 컬렉션/필드"를 삭제할 수 있고, 관련 레코드 데이터도 삭제될 수 있으니 주의.
bash curl -sS -X PUT "${PB_URL}/api/collections/import" \ -H "Authorization: ${PB_TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "collections": [ { "name": "collection1", "type": "base", "fields": [ { "name": "status", "type": "bool" } ] }, { "name": "collection2", "type": "base", "fields": [ { "name": "title", "type": "text" } ] } ], "deleteMissing": false }' \ -o /dev/null -w "%{http_code}\n"
GET /api/collections/meta/scaffoldsScaffoldsjson { "auth": { "type": "auth", "fields": [ /* default fields */ ], "...": "..." }, "base": { "type": "base", "fields": [ /* default fields */ ], "...": "..." }, "view": { "type": "view", "fields": [ /* empty by default */ ], "viewQuery": "" } }
bash curl -sS "${PB_URL}/api/collections/meta/scaffolds" \ -H "Authorization: ${PB_TOKEN}"
PB_URL, PB_ADMIN_EMAIL, PB_ADMIN_PASSWORD 확보_superusers/auth-with-password로 PB_TOKEN 획득deleteMissing=true)PB_URL에 /api를 중복으로 붙이지 않았나? (base는 host까지만)Authorization: <token> 헤더 형식이 맞나?deleteMissing=true를 의도했나?Other measured skills in the registry, with their headline benchmark lift.