Print Jobs API
Print Jobs API
创建打印任务
POST /v1/print-jobs
请求:
用 GET /v1/printers 返回的 printer_code 指定打印机。已有集成仍可继续传 printer_id。
可二选一提交:content 填 base64 内容,或 content_url 填公网 HTTP/HTTPS URL。
Base64 内容:
{
"printer_code": 1000000,
"content_type": "pdf",
"content": "JVBERi0xLjQK...",
"copies": 1,
"options": { "duplex": false }
}公网 URL:
{
"printer_code": 1000000,
"content_type": "pdf",
"content_url": "https://example.com/label.pdf",
"copies": 1,
"options": { "duplex": false }
}返回:
{ "id": "job_abc", "status": "queued" }本地 Agent 打印
桌面版 Agent 启用本地网页打印后,会监听本机 loopback 地址
http://127.0.0.1:17891。浏览器代码可以调用同一路径和接近一致的请求结构:
POST http://127.0.0.1:17891/v1/print-jobs
本地 Agent 会直接在用户电脑上打印。打印完成后,Agent 会异步把任务记录回云端; 浏览器请求不会被云端记录请求阻塞。
本地请求体与云端创建任务保持一致:
{
"printer_code": 1000000,
"content_type": "pdf",
"content_url": "https://example.com/label.pdf",
"copies": 1,
"options": { "source": "dashboard_url" }
}当系统打印队列接受任务后,本地接口会返回本地任务 ID 和完成状态:
{
"id": "local_1nk5ajf4zq",
"status": "completed",
"printer_code": 1000000,
"delivery_mode": "local_agent"
}记录本地任务
POST /v1/print-jobs/local-records
这个接口只给可信 PrintBase Agent 使用。它用于给已经本地打印的任务补云端历史,
不会加入云端派发队列。普通集成仍应调用 POST /v1/print-jobs。
查询任务
GET /v1/print-jobs/{id}
示例返回:
{
"id": "job_abc",
"status": "printing",
"printer_id": "printer_123",
"printer_code": 1000000,
"content_type": "pdf",
"content_url": "https://example.com/label.pdf",
"copies": 1,
"options": { "duplex": false },
"created_at": "2026-06-17T11:55:27Z",
"updated_at": "2026-06-17T11:55:29Z"
}返回不会包含内联 base64 content。
状态机
queued -> dispatched -> printing -> completed
失败原因:
AGENT_OFFLINEPRINTER_OFFLINEDOWNLOAD_FAILEDPRINT_ERRORINVALID_CONTENT