观远数据 API Skill
Description
This skill provides a command-line interface for GuanYuan Data (观远数据) API. It supports multiple authentication methods, automatic token management, card data retrieval, and CSV export with metadata generation.
Usage Instructions
When a user requests GuanYuan data operations:
- 1. Choose authentication method:
- Method 1: Provide
loginId and
password in config for automatic login
- Method 2: Provide
token directly in config file
- Method 3: Use
guanyuan token <token> command to set token interactively
- 2. Get card data: Use
guanyuan card <cardId> to retrieve data in JSON format
- 3. Export to CSV: Use
guanyuan csv <cardId> --output file.csv to export data
Authentication Methods
Method 1: Automatic Login with Credentials
{
"baseUrl": "https://your-guanyuan-domain.com",
"domain": "your-domain",
"loginId": "your-login-id",
"password": "your-password"
}
Then run: INLINECODE6
Method 2: Direct Token in Config
{
"baseUrl": "https://your-guanyuan-domain.com",
"domain": "your-domain",
"token": "your-token-here"
}
No login needed, directly use commands.
Method 3: Token Command (Interactive)
{
"baseUrl": "https://your-guanyuan-domain.com",
"domain": "your-domain"
}
Then run:
guanyuan token <your-token> or
guanyuan token (interactive)
Available Resources
Main Script
- - scripts/guanyuan.js: Main CLI tool
-
login(): Authenticate and save token
-
getCardData(cardId, options): Retrieve card data
-
convertToCSV(cardData, sampleRows): Convert data to CSV format
-
extractMetadata(cardData): Extract field metadata
-
saveCSVWithMetadata(csv, filename, metadata, cardId): Save CSV and metadata files
-
getValidToken(config): Auto-discover and use valid token from multiple sources
Configuration Files
- - ~/.guanyuan/config.json: API credentials and settings
- Required:
baseUrl,
domain
- Optional (one of):
loginId +
password,
token, or none (use token command)
- - ~/.guanyuan/user.token: Stored authentication token (auto-managed)
Export Files
- - .csv: CSV data file
- _meta.json: Metadata file with field information
References
- - references/README.md: Detailed user documentation in Chinese
Commands Reference
| Command | Description | Example |
|---|
| INLINECODE20 | Initialize configuration (show setup instructions) | INLINECODE21 |
| INLINECODE22 |
Login with credentials from config |
guanyuan login |
|
token [token] | Set token (via parameter or interactive) |
guanyuan token eyJ0eX... |
|
card <id> | Get card data (JSON) |
guanyuan card abc123 --limit 50 |
|
csv <id> | Export to CSV |
guanyuan csv abc123 --output data.csv |
|
status | Show config and token status |
guanyuan status |
|
help | Show help |
guanyuan help |
Options Reference
Common Options
| Option | Description | Default |
|---|
| INLINECODE34 | Data view type | GRAPH |
| INLINECODE35 |
Number of rows | 100 |
|
--offset <number> | Data offset | 0 |
CSV Export Options
| Option | Description | Default |
|---|
| INLINECODE37 | Output to file | stdout |
| INLINECODE38 |
Sample N rows | all rows |
Example Prompts
- - "使用账号密码登录观远数据并获取卡片abc123的数据"
- "使用token设置观远数据认证"
- "Export card data to CSV with metadata"
- "Get the first 50 rows of card l059d768f28bd404caf8df3e"
- "导出卡片数据到CSV文件,只采样前10行"
- "Check GuanYuan API configuration status"
- "Save card data as query_data.csv with metadata"
- "Set token for GuanYuan API without providing credentials"
Authentication Workflow
CODEBLOCK3
Metadata File Format
When exporting CSV with --output, a _meta.json file is automatically generated:
CODEBLOCK4
Output Format
JSON Output
- - Full API response with chart data
- Includes dimensions, metrics, and formatting info
- Suitable for debugging and data inspection
CSV Output
- - Tabular format with headers
- Dimensions first, then metrics
- Proper CSV escaping for special characters
- Metadata file with field types and descriptions
Token Management
Token Sources (Priority Order)
- 1.
~/.guanyuan/user.token - Saved token (highest priority) config.json - Token field in config- Auto-login - Using
loginId + password from config
Token Behavior
- - With expireAt: Automatically validated against expiration time
- Without expireAt: Used indefinitely (user-manually set tokens)
- Expired/Invalid: Triggers auto-refresh (if credentials available) or prompts user
Manual Token Setting
CODEBLOCK5
Notes
- - Flexible Authentication: Three authentication methods for different use cases
- Token Management: Tokens are automatically discovered from multiple sources
- Auto-Login: Credentials-based auth with automatic token refresh
- Password Handling: Passwords are automatically Base64 encoded before API call
- URL Support: baseUrl can include protocol prefix (http:// or https://)
- CSV Escaping: Special characters (commas, quotes, newlines) are properly escaped
- File Safety: Existing files are overwritten without warning
- Data Limits: Use
--limit to control API response size - Sampling: Use
--sample to export only N rows without fetching all data - No Credentials Required: Can work with just baseUrl + domain + token command
API References
观远数据 API 技能
描述
该技能为观远数据 API 提供命令行界面。支持多种认证方式、自动令牌管理、卡片数据检索以及带元数据生成的 CSV 导出功能。
使用说明
当用户请求观远数据操作时:
- 1. 选择认证方式:
- 方式 1:在配置中提供 loginId 和 password 进行自动登录
- 方式 2:在配置文件中直接提供 token
- 方式 3:使用 guanyuan token
命令交互式设置令牌
- 2. 获取卡片数据:使用 guanyuan card 以 JSON 格式检索数据
- 3. 导出为 CSV:使用 guanyuan csv --output file.csv 导出数据
认证方式
方式 1:使用凭据自动登录
json
{
baseUrl: https://your-guanyuan-domain.com,
domain: your-domain,
loginId: your-login-id,
password: your-password
}
然后运行:guanyuan login
方式 2:在配置中直接使用令牌
json
{
baseUrl: https://your-guanyuan-domain.com,
domain: your-domain,
token: your-token-here
}
无需登录,直接使用命令。
方式 3:令牌命令(交互式)
json
{
baseUrl: https://your-guanyuan-domain.com,
domain: your-domain
}
然后运行:guanyuan token 或 guanyuan token(交互式)
可用资源
主脚本
- - scripts/guanyuan.js:主 CLI 工具
- login():认证并保存令牌
- getCardData(cardId, options):检索卡片数据
- convertToCSV(cardData, sampleRows):将数据转换为 CSV 格式
- extractMetadata(cardData):提取字段元数据
- saveCSVWithMetadata(csv, filename, metadata, cardId):保存 CSV 和元数据文件
- getValidToken(config):从多个来源自动发现并使用有效令牌
配置文件
- - ~/.guanyuan/config.json:API 凭据和设置
- 必需:baseUrl、domain
- 可选(之一):loginId + password、token,或留空(使用令牌命令)
- - ~/.guanyuan/user.token:存储的认证令牌(自动管理)
导出文件
- - .csv:CSV 数据文件
- _meta.json:包含字段信息的元数据文件
参考资料
- - references/README.md:详细的中文用户文档
命令参考
| 命令 | 描述 | 示例 |
|---|
| init | 初始化配置(显示设置说明) | guanyuan init |
| login |
使用配置文件中的凭据登录 | guanyuan login |
| token [token] | 设置令牌(通过参数或交互式) | guanyuan token eyJ0eX... |
| card | 获取卡片数据(JSON) | guanyuan card abc123 --limit 50 |
| csv | 导出为 CSV | guanyuan csv abc123 --output data.csv |
| status | 显示配置和令牌状态 | guanyuan status |
| help | 显示帮助 | guanyuan help |
选项参考
通用选项
| 选项 | 描述 | 默认值 |
|---|
| --view <GRAPH\ | GRID> | 数据视图类型 | GRAPH |
| --limit <number> |
行数 | 100 |
| --offset | 数据偏移量 | 0 |
CSV 导出选项
| 选项 | 描述 | 默认值 |
|---|
| --output <filename> | 输出到文件 | 标准输出 |
| --sample <number> |
采样 N 行 | 所有行 |
示例提示
- - 使用账号密码登录观远数据并获取卡片abc123的数据
- 使用token设置观远数据认证
- Export card data to CSV with metadata
- Get the first 50 rows of card l059d768f28bd404caf8df3e
- 导出卡片数据到CSV文件,只采样前10行
- Check GuanYuan API configuration status
- Save card data as query_data.csv with metadata
- Set token for GuanYuan API without providing credentials
认证工作流程
┌─────────────────────────────────────────────────────────────┐
│ 用户想要访问观远数据 │
└────────────────────┬────────────────────────────────────────┘
│
v
┌─────────────────────────────────────────────────────────────┐
│ 检查 ~/.guanyuan/user.token │
│ 是否存在有效令牌? │
└────────────────────┬────────────────────────────────────────┘
│
┌────────┴────────┐
│ │
是 │ │ 否
│ │
v v
┌───────────────────┐ ┌──────────────────────────────────┐
│ 使用已保存的令牌 │ │ 检查 config.json │
└───────────────────┘ │ - 是否有 loginId + password? │
│ - 是否有 token? │
│ - 都没有?→ 使用 token 命令 │
└────────────┬─────────────────────┘
│
┌──────────────┼──────────────┐
│ │ │
有凭据 有令牌 都没有
│ │ │
v v v
┌───────────┐ ┌───────────┐ ┌───────────────┐
│ 自动 │ │ 使用 │ │ 提示用户 │
│ 登录 │ │ 配置 │ │ 运行 │
│ │ │ 令牌 │ │ guanyuan │
└───────────┘ └───────────┘ │ token │
└───────────────┘
元数据文件格式
使用 --output 导出 CSV 时,会自动生成 _meta.json 文件:
json
{
cardId: card-id,
cardType: CHART,
chartType: PIVOT_TABLE,
view: GRAPH,
exportTime: 2026-03-25T07:52:00.924Z,
totalRows: 10,
dataLimit: 10,
hasMoreData: false,
fields: [
{
name: 字段显示名称,
originalName: 字段原始名称,
type: STRING/TIMESTAMP/DOUBLE,
metaType: DIM/METRIC,
fieldType: dimension/metric,
fieldId: field-id
}
]
}
输出格式
JSON 输出
- - 包含图表数据的完整 API 响应
- 包含维度、度量和格式化信息
- 适用于调试和数据检查
CSV 输出
- - 带表头的表格格式
- 维度在前,度量在后
- 特殊字符的 CSV 转义处理
- 包含字段类型和描述的元数据文件
令牌管理
令牌来源(优先级顺序)
- 1. ~/.guanyuan/user.token - 已保存的令牌(最高优先级)
- config.json - 配置中的令牌字段
- 自动登录 - 使用配置中的 loginId + password
令牌行为
- - 有过期时间:自动验证是否过期
- 无过期时间:无限期使用(用户手动设置的令牌)
- 过期/无效:触发自动刷新(如有凭据)或提示用户
手动设置令牌
bash
通过参数
guanyuan token eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...
交互模式
guanyuan token
然后在提示时粘贴您的令牌
注意事项
- - 灵活的认证:三种认证方式适用于不同使用场景
- 令牌管理:令牌会自动从多个来源发现
- 自动登录:基于凭据的认证,支持自动令牌刷新
- 密码处理:密码在 API 调用前