API 参考

认证与令牌

所有 GraphQL 请求都需要在 Authorization 头中携带 Bearer token,并在 c-id(客户端 ID)头中携带客户端 ID。两者均可从 PlainApp Settings → Sessions & API Tokens 获取。ADB token 是独立的,仅用于 Android 自动化来启动或停止 HTTP 服务器——可在 Settings → Developer Options 中找到。

类型定义

bash
# GraphQL requests must include both headers:
c-id: <client-id>
Authorization: Bearer <api-token>

# Endpoint : POST /graphql

操作

http

API Token

在 PlainApp Settings → Sessions & API Tokens → API Tokens 标签页中创建 API token。每个 token 包含一个客户端 ID 和一个 token 值。将两者作为请求头发送:c-id 用于客户端 ID,Authorization: Bearer 用于 token。

bash
# On your Android device:
# 1. Open PlainApp
# 2. Go to Settings → Sessions & API Tokens
# 3. Open the "API Tokens" tab
# 4. Tap + to create a new token
# 5. Copy the c-id and token values shown

curl --request POST \
  --url http://192.168.1.100:8080/graphql \
  --header 'c-id: <your-client-id>' \
  --header 'Authorization: Bearer <your-api-token>' \
  --header 'Content-Type: application/json' \
  --data '{"query":"{ chatItems { content } }"}'
app

ADB Token

ADB token 专用于 Android 自动化——通过 adb broadcast 启动和停止 PlainApp HTTP 服务器。可在 PlainApp Settings → Developer Options 中找到。它不是用于 GraphQL 请求的 Bearer token。

bash
# Start the HTTP server
adb shell am broadcast -a com.ismartcoding.plain.action.START_HTTP_SERVER -p com.ismartcoding.plain --es token <your-adb-token>

# Stop the HTTP server
adb shell am broadcast -a com.ismartcoding.plain.action.STOP_HTTP_SERVER -p com.ismartcoding.plain --es token <your-adb-token>
app

plainapp-cli (AI Agent)

plainapp-cli 是一款 Rust 命令行工具,专为 AI 可调用的 CLI 设计。将它交给任何能够运行 shell 命令的 AI agent,即可让该 agent 通过 PlainApp GraphQL API 检查和控制手机数据——联系人、SMS、文件、笔记、通话等。

bash
# Install (macOS & Linux one-liner)
bash <(curl -fsSL https://raw.githubusercontent.com/plainhub/plainapp-cli/main/install.sh)

# Or build from source (requires Rust ≥ 1.75)
cargo install --path .

# --- Setup ---
# 1. Open PlainApp → Settings → Sessions & API Tokens → API Tokens tab
# 2. Tap + to create a token, note the Client ID and Token
# 3. Run to generate config:
plainapp-cli --init
# Edit ~/.config/plainapp-cli/config.toml:
# api_url   = "https://192.168.1.100:8443"
# client_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
# token     = "BASE64_ENCODED_32_BYTE_TOKEN"

# --- Usage ---
# Fetch the full GraphQL schema (for AI introspection)
plainapp-cli --schema

# Execute any GraphQL query or mutation
plainapp-cli --exec '<json>'

# Examples:
# List SMS conversations
plainapp-cli -e '{"query":"{ smses(limit:20,offset:0) { id address body date } }","variables":null}'

# List notes
plainapp-cli -e '{"query":"{ app { battery sdcardPath } }","variables":null}'

# Delete a file
plainapp-cli -e '{
  "query": "mutation DeleteFiles($paths:[String!]!) { deleteFiles(paths:$paths) }",
  "variables": {"paths":["/sdcard/tmp/test.txt"]}
}'