Print API

Send labels to Device Hub for secure printing

Print API

The Print API sends unredacted labels from Data Border storage to your tenant's Device Hub for secure printing.

Send Print Job

Sends labels to a printer via the tenant's configured Device Hub.

POST /api/print/send

Authentication

HeaderRequiredDescription
x-seller-access-tokenYesValid seller access token
x-amazon-token-secretYesSecret used during OAuth

Request Body

{
  "shipment_id": "ship_abc123def456",
  "printer_type": "label",
  "printer_id": "warehouse-zebra-01",
  "label_uuids": ["550e8400-e29b-41d4-a716-446655440000"]
}
FieldTypeRequiredDescription
shipment_idstringYesData Border shipment ID from label proxy/passthrough
printer_typestringYes"label" (thermal) or "laser"
printer_idstringYesPrinter identifier in Device Hub
label_uuidsstringYesDocument UUIDs to print

Response

{
  "success": true,
  "data": {
    "status": "sent",
    "shipment_id": "ship_abc123def456",
    "documents_sent": 1,
    "print_count": 1,
    "is_reprint": false
  }
}
FieldDescription
status"sent" on success
shipment_idThe shipment that was printed
documents_sentNumber of documents sent to printer
print_countTotal times this shipment has been printed
is_reprintWhether this is a reprint

Reprint Detection

When a shipment has been printed before:

{
  "success": true,
  "data": {
    "status": "sent",
    "shipment_id": "ship_abc123def456",
    "documents_sent": 1,
    "print_count": 2,
    "is_reprint": true,
    "warning": "Reprint detected. First printed: 2024-01-15T10:30:00.000Z"
  }
}

Example

curl -X POST "https://adb.example.com/api/print/send" \
  -H "Content-Type: application/json" \
  -H "x-seller-access-token: YOUR_SELLER_TOKEN" \
  -H "x-amazon-token-secret: YOUR_TOKEN_SECRET" \
  -d '{
    "shipment_id": "ship_abc123def456",
    "printer_type": "label",
    "printer_id": "warehouse-zebra-01",
    "label_uuids": ["550e8400-e29b-41d4-a716-446655440000"]
  }'

Errors

StatusMessageCause
400shipment_id is requiredMissing shipment ID
400Invalid printer_typeMust be label or laser
400Invalid label UUIDsUUIDs not part of shipment
404Shipment not foundShipment doesn't exist
400Device Hub not configuredTenant lacks Device Hub setup

Flow Diagram

Loading diagram...

Device Hub Configuration

Device Hub must be configured for your tenant. Contact your Data Border administrator to set up:

SettingDescription
device_hub_hostBase URL of your Device Hub instance
device_hub_api_keyAPI key for authentication

Label Printer

Optimized for thermal label printers (Zebra, DYMO, etc.):

{
  "printer_type": "label",
  "printer_id": "zebra-zd420"
}
  • Sends native ZPL if available
  • Falls back to PDF/image conversion
  • Standard 4x6" label format

Laser Printer

For standard office printers:

{
  "printer_type": "laser",
  "printer_id": "hp-laserjet-m404"
}
  • Sends PDF format
  • Supports multiple labels per page
  • Letter/A4 paper format

Implementation Example

async function printShipmentLabels(shipment, printerId) {
  const { token, secret } = await tokenManager.getSellerAccessToken(shipment.sellerId)
  
  const response = await fetch(`${ADB_URL}/api/print/send`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'x-seller-access-token': token,
      'x-amazon-token-secret': secret
    },
    body: JSON.stringify({
      shipment_id: shipment.adbShipmentId,
      printer_type: 'label',
      printer_id: printerId,
      label_uuids: shipment.documents.map(d => d.uuid)
    })
  })
  
  const data = await response.json()
  
  // Handle reprints
  if (data.data.is_reprint) {
    await logReprintWarning(shipment, data.data)
    
    // Optional: require confirmation for reprints
    if (!await confirmReprint(shipment)) {
      throw new Error('Reprint cancelled by user')
    }
  }
  
  // Update shipment record
  await db.shipments.update(shipment.id, {
    printCount: data.data.print_count,
    lastPrinted: new Date()
  })
  
  return data.data
}

Handling Reprints

Why Track Reprints?

Reprints may indicate:

  • Lost or damaged labels
  • Printer issues
  • Potential label fraud
  • Process inefficiencies

Reprint Monitoring

// Alert on excessive reprints
async function monitorReprints() {
  const reprints = await db.shipments.findMany({
    where: { 
      printCount: { gt: 1 },
      lastPrinted: { gt: oneDayAgo }
    }
  })
  
  if (reprints.length > threshold) {
    await alertOperations('High reprint rate detected', reprints)
  }
}

Audit Trail

All print operations are logged:

{
  "type": "print",
  "shipment_id": "ship_abc123",
  "documents": ["uuid1", "uuid2"],
  "printer_id": "zebra-01",
  "print_count": 2,
  "is_reprint": true,
  "timestamp": "2024-01-15T10:30:00.000Z"
}

Best Practices

Batch Printing

Print all documents in a single request:

// Good: Single request for all docs
await print({
  shipment_id: shipment.id,
  label_uuids: shipment.documents.map(d => d.uuid)
})

// Avoid: Multiple requests
for (const doc of shipment.documents) {
  await print({ shipment_id: shipment.id, label_uuids: [doc.uuid] })
}

Error Recovery

async function printWithRetry(shipment, printerId, retries = 3) {
  for (let i = 0; i < retries; i++) {
    try {
      return await printLabels(shipment, printerId)
    } catch (error) {
      if (error.message.includes('Device Hub not configured')) {
        // Configuration error - don't retry
        throw error
      }
      if (i < retries - 1) {
        await delay(1000 * (i + 1)) // Exponential backoff
      }
    }
  }
  throw new Error('Print failed after retries')
}

Next Steps

Secure Printing

Understand the end-to-end print security.

Label Proxy

Generate labels to print.