
When migrating automated workflows to for example custom Python scripts, you often need the exact API tokens, secrets, or chat parameters configured inside your self-hosted n8n instance.
Because the n8n web UI masks sensitive values (displaying dots or grayed-out inputs), you cannot simply copy-paste tokens from the web browser. However, since you host the instance, you can bypass UI masking and extract decrypted credentials or workflow data directly via the n8n CLI.
1. Extracting Decrypted API Credentials via Docker
n8n encrypts all stored credentials in its internal database. Using the --decrypted flag with the built-in server CLI allows you to dump all access tokens, API keys, and secret pairs in plain text directly to standard output.
Command Execution
Run the following command against your running n8n container (node user):
docker exec -u node n8n export:credentials --all --decrypted
Output Example
The command returns a clean JSON array containing all decrypted authentication fields:
[ { "id": "1", "name": "Telegram account", "type": "telegramApi", "data": { "accessToken": "123456789:ABCdefGhIJKlmNoPQRsTUVwxyZ" } } ]
2. Exporting Workflows to File & Extracting Target IDs with jq
Workflow files can be extremely large when exported to terminal standard output. To inspect target settings—such as Telegram chatId fields, webhook URLs, or channel names—export the workflows directly to a file on your host machine and filter the JSON tree using jq.
Step 1: Export Workflows to Host JSON File
Redirect the n8n workflow export directly to a local JSON file:
docker exec -u node n8n export:workflow --all > n8n-workflows.json
Step 2: Query Specific Fields across All Nodes with jq
Because workflows contain deeply nested node parameters, use jq’s recursive descent operator (..) to extract specific properties across all configured nodes regardless of workflow complexity.
To find all Telegram target IDs (chatId or chat_id keys):
jq '.. | .chatId? // .chat_id? | select(. != null)' n8n-workflows.json
Output Example
"987654321" "-1001234567890"
Summary Cheat Sheet
| Task | Command |
|---|---|
| Dump Decrypted Secrets | docker exec -u node n8n export:credentials –all –decrypted |
| Export Workflows to Host | docker exec -u node n8n export:workflow –all > workflows.json |
| Extract Specific Key via jq | jq ‘.. | .<KEY_NAME>? | select(. != null)’ workflows.json |