PrintSpirit HTTP REST API Documentation

Before use, please download and install SpiritCenter server program

Use Cases

The REST API is one of the PrintSpirit development modes, suitable for scenarios requiring centralized management of label printing tasks. The server with SpiritCenter installed can connect to multiple printers (including specialized barcode printers like Zebra or regular Windows printers). Other devices on the LAN can submit label printing requests via REST API to achieve remote printing control.

PC Print Client Mobile Device Print Client /print REST API SpiritCenter Server USB/Network Print Commands Printer 1 ZPL Printer 2 TSPL

The REST API itself does not provide label editing functionality. For label editing, please refer to Embedding "PrintSpirit" Label Editor.

Basic Information

  • Protocol: HTTP
  • Default Port: 9011 (if occupied, uses 19011). HTTPS: 9443 (if occupied, uses 19443)
  • Request Format: JSON (UTF-8)
  • Response Format: JSON (UTF-8)

Common Response Structure

1{
2  "rc": "OK/ERR", 
3  "cnt": 1,          // Only returned by print interface
4  "msg": "Additional message"
5}

API Endpoints Details

1. Print Label

  • URL: /print
  • Method: POST
  • Headers: Content-Type: application/json

Request Body Structure

 1{
 2  "cmd": "PrintLabel",
 3  "data": {
 4    "tpid": "Label Template ID",
 5    "vars": [ 
 6      { /* Variable Data Object */ } 
 7    ]
 8  },
 9  "opts": {
10    "printer": "Printer Name",
11    "type": "ZPL/CPCL/TSPL/ESCPOS",
12    "row": 1,         // Number of rows
13    "col": 1,         // Number of columns
14    "size": 50,       // Or [100,200]
15    "gapX": 2,        // Horizontal gap (mm)
16    "gapY": 3,        // Vertical gap (mm)
17    "quality": 0,     // 0-Fast,1-Middle,2-High
18    "flush": true     // Immediate print
19  }
20}

Example Request

 1curl -X POST http://192.168.1.100:9011/print \
 2-H "Content-Type: application/json" \
 3-d '{
 4  "cmd": "PrintLabel",
 5  "data": {
 6    "tpid": "product_label",
 7    "vars": [{"sku": "A001", "qty": 100}]
 8  },
 9  "opts": {
10    "printer": "Zebra_01",
11    "type": "ZPL",
12    "row": 2,
13    "col": 1,
14    "quality": 2
15  }
16}'

2. Reset Printer

  • URL: /reset-printer
  • Method: POST
  • Headers: Content-Type: application/json

Request Body Structure

1{
2  "printer": "Printer Name"
3}

Example Request

1curl -X POST http://192.168.1.100:9011/reset-printer \
2-H "Content-Type: application/json" \
3-d '{"printer": "Zebra_01"}'

3. Clear Cache

  • URL: /clear-cache
  • Method: GET
  • Response: 204 No Content (on success)

Example Request

1curl -X GET http://192.168.1.100:9011/clear-cache

4. Register Virtual Printer

  • URL: /register-printer
  • Method: POST
  • Headers: Content-Type: application/json

Request Body Structure

1{
2  "printer": "Virtual Printer Name",
3  "type": "ZPL/CPCL/TSPL/ESCPOS",
4  "row": 1,
5  "col": 1,
6  // ...Other parameters same as print interface
7}

Success Response

1{
2  "rc": "OK",
3  "token": "d3b07384d113e0ec49eaa6238ad5ff00"
4}

5. Get Rendered Data (Virtual Printer)

Retrieve virtual printer queue data through other methods. Data format:

BASE64(ZLIB-compressed(raw print commands))

Decoding Example

Raw data: eJxLTE4sSc0vyklRBAAAMgMK Decoded: ^XA^FO50,50^A0N,50^FDHELLO WORLD^FS^XZ


Error Handling

HTTP Status Codes

Code Description
200 General success
204 Cache cleared
400 Invalid request
500 Server error

Error Response Example

1{
2  "rc": "ERR",
3  "msg": "Printer offline"
4}

Protocol Details

Parameter Type Description
printer string Required Printer name
type enum Printer language type
row/col int Label matrix dimensions
size int/array Label size (mm)
gapX/gapY int Label gaps (mm)
quality 0/1/2 Print quality level
flush bool Immediate submission

Next: REST API Java SDK


Leave Your Message

login