Skip to main content

CLI Usage Guide


HAP CLI wraps HAP backend capabilities into a command-line interface, enabling automation and AI-driven operations across the platform.

It covers three major scenarios:

  1. Collaboration & Communication

    • Access contacts and departments
    • Send and receive direct messages and group chats
    • Publish posts
    • Manage calendars
  2. Application Data

    • Read and write worksheet records (CRUD, filtering, pivot analysis)
    • Execute workflows
    • Handle approval to-dos
    • Manage custom pages and roles/permissions
    • Upload files
  3. Application Modification

    • Perform precise updates to existing applications
    • Add fields, modify views, adjust workflows, etc.

When used with AI, CLI enables natural-language-driven control of the entire HAP platform.

Installation

pip install hap-cli

Prerequisite: Enable CLI Access

CLI access must be enabled at the organization level before hap can access data.

Organization administrators can enable it in:

Organization Admin Console > Security > Data & Access > CLI Access Policy

If disabled, CLI commands will be blocked.

You can check status via:

hap auth list-my-orgs

(CLI:on/off indicates whether CLI access is enabled.)

Login

# Default HAP SaaS environment
hap auth login

# Explicit environment selection
hap auth login mingdao # Production
hap auth login nocoly # Nocoly SaaS
hap auth login https://hap.example.com # HAP Server

Non-interactive login (scripts / headless servers)

hap auth login https://your-server.com --token YOUR_TOKEN


The browser flow will open for authentication and token retrieval.

If CLI cannot receive callback (e.g., no GUI or restricted network), cancel the command and manually paste the token shown in the browser.

```bash
hap auth whoami # Current user, org, and environment
hap auth logout # Log out current account

Multi-Environment / Multi-Account Support

HAP CLI supports multiple environments (Mingdao SaaS, Nocoly, HAP Server) and multiple accounts.

Each session can be saved as a named profile for reuse.

hap auth login mingdao --profile work-prod        # Log in and save as a named profile
hap auth login https://hap.example.com --profile onprem
# If --profile is omitted, a profile name is auto-generated from the server URL.
# New logins do not overwrite existing profiles.

hap auth accounts # List all environments/accounts (current one marked with *)
hap auth use work-prod # Switch current active environment/account
hap --profile onprem app list # Use a specific environment/account for this single command only
HAP_PROFILE=onprem hap app list # Set default environment/account for the entire terminal session

hap auth logout -p onprem # Log out of a specified account
hap auth logout --all # Log out of all accounts

Profile priority order:

--profile > HAP_PROFILE environment variable > current active profile

Organization and Application Selection

hap auth list-my-orgs                     # Active organization marked with *
hap auth set-current-org ORG_ID # Set default organization

hap app list # Use default organization
hap app list --org-id ORG_ID # Override organization

# Set default application --app-id can be omitted in subsequent commands
hap app select APP_ID
hap app unselect # Clear default application

Switching default organization (hap auth set-current-org) will clear the default application, since applications belong to organizations. Use hap app select to set a new default app.

Browse Worksheets & Records

hap app info APP_ID                          # App structure overview (groups, worksheets and custom pages)
hap worksheet list # Worksheets in default app
hap worksheet info WORKSHEET_ID # Full worksheet schema (fields + settings)
hap worksheet field-types # Field type reference
hap worksheet record list WORKSHEET_ID --page-size 10

JSON Output Mode

hap --json worksheet record list WORKSHEET_ID

All commands support --json for machine-readable output (useful for scripting and automation).

Default App and Organization Resolution

For any command requiring --app-id, resolution follows:

  1. Explicit --app-id in command
  2. Default app selected via hap app select APP_ID
  3. Error if still not resolved (prompting user to set default app)

REPL Mode

hap repl
hap> worksheet record list WORKSHEET_ID
hap> --json workflow list
hap> approval todo-count
hap> quit
  • hap prefix can be omitted
  • Prefix with --json to switch output format

Command Reference

You can use hap <group> --help at any level to view full subcommands.

auth — Authentication & Sessions

CommandDescription
auth login [SERVER]Browser-based login (--token for non-interactive mode; --profile NAME saves a named profile; --force reassigns an existing profile)
auth accountsList all environments/accounts (current marked with *)
auth use NAMESwitch active environment/account
auth logoutLog out current account (-p NAME for specific one, -a/--all for all accounts)
auth whoamiShow current user, environment/account, and organization
auth list-my-orgsList organizations under the current account (current marked with *, includes CLI:on/off status)
auth set-current-org ORG_IDSet default organization (switching default org clears default app)

app — Application Management

CommandDescription
app listList applications in the organization (default app marked with *)
app list-managedList applications where the user is an administrator
app info APP_IDView application details (groups, worksheets, custom pages)
app create / update / deleteApplication lifecycle operations
app select APP_ID / unselectSet or clear default application
app create-section / edit-section / delete-sectionGroup management
app sort-sections / sort-worksheetsReorder groups or worksheets
app create-itemCreate empty worksheets or custom pages in batch
app backup / export / exports / backup-logsBackup and export
app usage / logsUsage statistics and operation logs
app role …Role CRUD, permissions, members, leave-all, and requests
app optionset …Option set CRUD and cross-app migration
app knowledge list / searchApplication knowledge base

worksheet — Worksheets, Views, Custom Actions & Charts

CommandDescription
worksheet list / info / fields / field-typesView worksheet structure
worksheet create / update / copy / deleteWorksheet lifecycle management
worksheet rules / save-ruleBusiness rules
worksheet switches / edit-switchFunction switch
worksheet form-settings / save-form-settingsForm submission and advanced settings
worksheet custom-actions / create-custom-action / delete-custom-actionCustom actions
worksheet create-chartCreate chart
worksheet view list / info / create / copy / delete / sortView management

worksheet record — Record CRUD

CommandDescription
worksheet record list / getQuery or retrieve records
worksheet record create / update / deleteSingle record CRUD
worksheet record batch-create / batch-updateBatch operations (including subform and related records)
worksheet record relations / share-linkRelated records and share links
worksheet record discussions / add-discussion / delete-discussionRecord comments
worksheet record logsSingle record change logs
worksheet record pivot / bottom-statsPivot analysis and summary statistics

workflow — Workflows & Nodes

CommandDescription
workflow list / get / structure / history / groups / statsView workflows
workflow create / update / copy / move / deleteWorkflow lifecycle
workflow publish / rollbackVersion management
workflow trigger / trigger-pbpManual trigger execution
workflow config-get / config-setGlobal configuration
workflow create-approval / update-approval / delete-approvalApproval containers
workflow node …Node CRUD, batch operations, testing (code/webhook/AI), controls, types, and code templates

approval — Approvals & To-dos

CommandDescription
approval todo / todo-count / todo-filters / archivedTo-dos and archived items
approval get / get-by-row / list-by-row / work-item / operations / op-history / history / history-detailInstance status
approval approve / reject / submit / sign / forward / urgeApproval actions
approval revoke / terminate / restart / retryInstance lifecycle operations
approval batch / retry-batch / end-batchBatch operations
approval list-typesEnumeration reference
approval delegation create / list / list-by-company / list-by-principals / updateApproval delegation

custom-page — Custom Pages

CommandDescription
custom-page info / save / update-configView and update layout
custom-page create / rename / copy / deleteLifecycle operations
custom-page component-typesComponent reference

contact — Contacts

CommandDescription
contact search / resolveSearch contacts / resolve accountId
contact friends / friend-requestsContacts
contact add-friend / accept-friend / reject-friend / ignore-friend / remove-friendFriend management

department — Departments

CommandDescription
department list / tree / info / members / searchDepartment queries

post — Posts

CommandDescription
post list / search / getView posts
post create / update / deleteCreate, edit, delete posts
post comment / comments / comment-deleteComment operations
post like / likes / favoriteLike and favorite actions
post pin / unpin / pinnedPin management
post topicsTopics

calendar — Calendar

CommandDescription
calendar list / get / create / update / deleteCalendar lifecycle management
calendar categoriesBuilt-in categories
calendar add-member / remove-memberParticipant management

chat — Chat & Messaging

CommandDescription
chat listRecent chats
chat messagesDirect/group/system messages (including workflow and app messages)
chat filesFiles shared in chats
chat sendSend plain text messages
chat group-infoGroup information
chat card-detailParse embedded card references in messages

region — Regions

CommandDescription
region getLookup by --id or fuzzy search using --search

icon — Icon Library

CommandDescription
icon searchSearch icons by English and Chinese keywords (union match; ranked by relevance; auto-supplement to 10 results if needed)
icon list [-n SIZE] [-p PAGE]Paginated icon list (default 50 per page)

upload — File Upload

CommandDescription
upload [SOURCES...]Upload local file paths or HTTP(S) URLs to storage and return a structured file descriptor object (fileID, key, url, serverName, filePath, fileName, fileExt, originalFileName, fileSize).

config — CLI Configuration

CommandDescription
config showShow CLI configuration summary
config completion [bash|zsh|fish] [--install]Enable shell command completion for <Tab> (bash, zsh, or fish).
config language [LANG]Switch CLI language (en, zh-Hans, zh-Hant, ja)
config log on / off / statusLogging control
config log level LEVELSet logging level
config log view [--lines N] [--no-follow]View log output

update — CLI Update

CommandDescription
updateCheck PyPI for the latest version and upgrade via pip/pipx/uv
update --checkCheck for updates without installing

Examples

# Create a record
hap worksheet record create WORKSHEET_ID -f "c001=value1" -f "c002=value2"

# Build a workflow
hap workflow create --name "My Flow" --app-id APP_ID
hap workflow node add PROCESS_ID --type 4 --name "Manager Approval"
hap workflow node save PROCESS_ID NODE_ID --config '{"accounts":[...]}'
hap workflow publish PROCESS_ID
hap workflow trigger PROCESS_ID --source-id ROW_ID

# Approvals
hap approval todo --type 4
hap approval approve INSTANCE_ID --opinion "OK"
hap approval reject INSTANCE_ID --opinion "Needs revision"
hap approval batch --action 4 -s ID1 -s ID2

# Roles
hap app role list
hap app role add-member ROLE_ID -u USER_ID

# Knowledge base search
hap app knowledge search --keyword "new employee onboarding" --mode hybrid

Was this document helpful?