Skip to main content
This guide will help you send your first print job through APM using the WebSocket API.

Prerequisites

Before you begin, make sure you have:
  • APM Windows Service installed and running (see Installation)
  • A thermal printer configured in APM
  • Basic knowledge of JavaScript and WebSocket connections

Step 1: Start the APM service

1

Verify the service is running

Check that the APM Windows Service is running. You can verify this through the Windows Services panel or the system tray icon.The WebSocket server should be listening on port 7000.
2

Check connectivity

Open your browser and navigate to:
http://localhost:7000/
You should see a status response indicating the server is running.

Step 2: Configure a printer

1

Open the MAUI application

Launch the APM configuration application from the Start Menu or desktop shortcut.
2

Add a printer

Navigate to the Printers section and click Add Printer. Configure your thermal printer with these settings:
  • Printer ID: main-printer
  • Connection Type: TCP/IP (or USB/IPP based on your setup)
  • IP Address: Your printer’s IP address (e.g., 192.168.1.100)
  • Port: 9100 (default for most thermal printers)
  • Paper Width: 80 mm (or 58 mm for smaller printers)
Click Save to apply the configuration.

Step 3: Send your first print job

Create an HTML file with the following code to send a print job via WebSocket:
<!DOCTYPE html>
<html>
<head>
    <title>APM Quickstart</title>
</head>
<body>
    <h1>APM Print Test</h1>
    <button onclick="sendPrintJob()">Send Print Job</button>
    <div id="status"></div>

    <script>
        let ws;
        
        // Connect to APM WebSocket server
        function connect() {
            ws = new WebSocket('ws://localhost:7000/websocket/');
            
            ws.onopen = () => {
                document.getElementById('status').innerHTML = 
                    '<p style="color: green;">Connected to APM!</p>';
            };
            
            ws.onmessage = (event) => {
                const message = JSON.parse(event.data);
                console.log('Received:', message);
                
                if (message.JobId) {
                    if (message.Status === 'DONE') {
                        document.getElementById('status').innerHTML += 
                            '<p style="color: green;">Print job successful!</p>';
                    } else if (message.Status === 'ERROR') {
                        document.getElementById('status').innerHTML += 
                            '<p style="color: red;">Print failed: ' + message.ErrorMessage + '</p>';
                    }
                }
            };
            
            ws.onerror = (error) => {
                document.getElementById('status').innerHTML = 
                    '<p style="color: red;">Connection error!</p>';
            };
        }
        
        function sendPrintJob() {
            const printJob = {
                Type: "PRINT_JOB_REQUEST",
                JobId: "test-" + Date.now(),
                StationId: "web-station",
                PrinterId: "main-printer",
                DocumentType: "ticket_venta",
                Document: {
                    Store: {
                        Name: "My Store",
                        Address: "123 Main Street",
                        Phone: "555-1234"
                    },
                    Sale: {
                        Number: "SALE-001",
                        Date: new Date().toISOString(),
                        Items: [
                            {
                                ProductName: "Product A",
                                Quantity: 2,
                                Price: 10.00,
                                Total: 20.00
                            },
                            {
                                ProductName: "Product B",
                                Quantity: 1,
                                Price: 15.50,
                                Total: 15.50
                            }
                        ],
                        Subtotal: 35.50,
                        Tax: 3.55,
                        Total: 39.05
                    },
                    Footer: [
                        "Thank you for your purchase!",
                        "Visit us again soon"
                    ]
                }
            };
            
            ws.send(JSON.stringify(printJob));
            document.getElementById('status').innerHTML += 
                '<p>Sending print job...</p>';
        }
        
        // Connect on page load
        connect();
    </script>
</body>
</html>
1

Save and open the HTML file

Save the code above as test-print.html and open it in your web browser.
2

Click the button

Click the Send Print Job button. You should see:
  1. Connection status showing “Connected to APM!”
  2. “Sending print job…” message
  3. “Print job successful!” confirmation
  4. Your thermal printer should print a sales receipt

Understanding the print job structure

The PrintJobRequest object contains:
Type
string
required
Must be "PRINT_JOB_REQUEST" for print jobs
JobId
string
required
Unique identifier for tracking the print job
StationId
string
required
Identifier for the workstation sending the request
PrinterId
string
required
Must match a printer ID configured in APM (e.g., "main-printer")
DocumentType
string
required
Type of document to print. Common types:
  • ticket_venta - Sales receipt
  • comanda - Kitchen order
  • factura_electronica - Electronic invoice
  • sticker - Barcode label
Document
object
required
The actual data to print. Structure varies by DocumentType. Must include fields referenced in your print template.

Next steps

Configure more printers

Set up multiple printers with different connection types

Customize templates

Design custom receipt layouts with the template editor

Integrate scales

Add scale data capture for weighing products

Explore the API

Learn about all available WebSocket API features

Troubleshooting

Cause: The APM Windows Service is not running or is listening on a different port.Solution:
  • Check if the service is running in Windows Services
  • Verify the WebSocket port is 7000 in the service configuration
  • Check Windows Firewall settings
Cause: The PrinterId doesn’t match any configured printer.Solution:
  • Open the APM MAUI application
  • Go to Printers section
  • Verify your printer ID matches exactly (case-sensitive)
  • Make sure the printer is enabled
Cause: No template exists for the specified DocumentType.Solution:
  • APM includes default templates for common document types
  • Check the Templates section in the MAUI app
  • Create a custom template if needed for your document type

Build docs developers (and LLMs) love