API mode (api)
Overview
The api mode allows executing direct calls to the Passwork API with responses in JSON format.
Syntax
- shell
passwork-cli api [options]
API parameters
The api command requires the following parameters:
| Parameter | Description |
|---|---|
--method | HTTP method (GET, POST, PUT, DELETE, PATCH) |
--endpoint | API path (e.g., v1/vaults) |
--params | JSON string with parameters (optional) |
--field | Field name to extract from the response (optional) |
How it works
- Authentication: Connects to the Passwork server;
- Request formation: Creates an HTTP request with the specified path and method;
- Request sending: Sends the request with the necessary authorization headers;
- Response handling: Receives and parses the API response;
- Filtering (optional): Extracts the specified field using
--field; - Output: The result is output in JSON format.
Usage examples
Get a list of all vaults:
- shell
passwork-cli api --method GET --endpoint "v1/vaults"
Get an item and extract only the name:
- shell
passwork-cli api --method GET --endpoint "v1/items/password_id" --field "name"
Search items by tags and get names from items:
- shell
passwork-cli api \
--method GET \
--endpoint "v1/items/search" \
--params '{"tags":["api","production"]}' \
--field "name"
Rotating accessToken and refreshToken:
- shell
passwork-cli api \
--host "https://passwork.example.com" \
--token "your_expired_token" \
--refresh-token "your_refresh_token" \
--method POST \
--endpoint "v1/sessions/refresh" \
--field "token"
Using with a self-signed certificate:
- shell
passwork-cli api --no-ssl-verify --method GET --endpoint "v1/user/profile"
Notes
- All responses are returned in JSON format;
- The
--fieldparameter allows extracting a specific field from the response; - The
--paramsparameter is used to pass data in POST, PUT, PATCH requests; - For self-signed certificates, you must use
--no-ssl-verify.