Tham chiếu API

Auth & Token

Tất cả yêu cầu GraphQL đều yêu cầu một Bearer token trong header Authorization và một header c-id (client ID). Lấy cả hai từ PlainApp Settings → Sessions & API Tokens. Token ADB là riêng biệt và chỉ được sử dụng cho tự động hóa Android để khởi động hoặc dừng máy chủ HTTP — tìm nó trong Settings → Developer Options.

Định nghĩa kiểu

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

# Endpoint : POST /graphql

Thao tác

http

API Token

Tạo một API token trong PlainApp Settings → Sessions & API Tokens → tab API Tokens. Mỗi token có một client ID và một giá trị token. Gửi cả hai dưới dạng header yêu cầu: c-id cho client ID và Authorization: Bearer cho 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

Token ADB được sử dụng độc quyền cho tự động hóa Android — khởi động và dừng máy chủ PlainApp HTTP qua adb broadcast. Tìm nó trong PlainApp Settings → Developer Options. Nó KHÔNG phải là Bearer token cho các yêu cầu GraphQL.

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 là một công cụ dòng lệnh Rust được thiết kế như một CLI có thể gọi bởi AI. Cấp nó cho bất kỳ AI agent nào có thể chạy lệnh shell để agent có thể kiểm tra và điều khiển dữ liệu điện thoại — liên hệ, SMS, tệp, ghi chú, cuộc gọi và hơn thế nữa — thông qua PlainApp GraphQL API.

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"]}
}'