PrintBase
  • Product
  • Pricing
  • Docs
  • Resources
PrintBase/Guides/Print from your language or framework

Print raw ZPL from Go

Go's net/http posts ZPL with no extra module. Base64 from encoding/base64. The agent prints the Zebra queue.

For Go services printing labels

This page in another language: 中文

Overview

The Go standard library is enough: bytes.Buffer or a string of ZPL, base64.StdEncoding, and http.NewRequest. Set the Idempotency-Key header. Do not depend on a printer daemon inside the container.

The marketing site lists an official Go SDK. This sample is the REST call. Module path and client types are not repeated here because the HTTP shape is the stable contract.

This page is the English counterpart of the Chinese Go ZPL page.

Create the job with POST /v1/print-jobs, an Authorization: Bearer header, printer_code, content_type pdf or raw, and exactly one of content or content_url. The free plan is 100 jobs a month on one computer.

Integration steps

  1. 01

    Create an API key on the server

    Use an API key (pb_live_…) in the process environment. Authorization is Bearer. Do not ship the key to browsers or mobile apps.

  2. 02

    Install the agent beside the printer

    Windows, macOS, or Linux. GET /v1/printers and keep the numeric code.

  3. 03

    POST /v1/print-jobs

    content_type is pdf or raw. Send exactly one of content (standard base64) or content_url.

  4. 04

    Reuse the idempotency key on retry

    A new key means a second physical print. HTTP 409 means the same key was reused with a different body.

  5. 05

    Read the job before you tell the user

    GET /v1/print-jobs/{id}. Paid plans can also receive print_job.completed and print_job.failed webhooks.

Go

// Go ZPL
body, _ := json.Marshal(map[string]any{
    "printer_code": printerCode,
    "content_type": "raw",
    "content": base64.StdEncoding.EncodeToString([]byte(zpl)),,
    "copies": 1,
})
req, _ := http.NewRequest(http.MethodPost, "https://api.printbase.cloud/v1/print-jobs", bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+os.Getenv("PRINTBASE_API_KEY"))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", idempotencyKey)
res, err := http.DefaultClient.Do(req)
if err != nil { log.Fatal(err) }
defer res.Body.Close()
// 201 {"id":"job_abc","status":"queued"}

Details for this setup

Context timeouts

Use http.NewRequestWithContext and a few-second timeout. A stuck dial should not park a goroutine for minutes.

JSON numbers

printer_code must be a JSON number, not a string, unless you have tested a string. Send the integer.

Questions

cgo and CUPS?

Unnecessary for a remote printer. The call is still POST /v1/print-jobs with a Bearer API key, and HTTP 201 means queued rather than printed.

Does the container need the Zebra driver?

No. The agent host needs it. The call is still POST /v1/print-jobs with a Bearer API key, and HTTP 201 means queued rather than printed.

bytes versus string?

ZPL is ASCII-compatible. Encode as UTF-8 and base64. Do not base64 the Go quoted syntax.

Retry policy?

Retry the same key on network errors. Do not generate a new key in the retry loop.

Related guides

  • Print a PDF from Go

    Read a PDF in Go and post it as base64. Use content_url if the object store link is public. No CGO PDF library is required to transport the file.

  • Print ZPL labels from Java

    Java's HttpClient can post ZPL. No printer JAR is required on the server. The agent prints the queue you name with printer_code.

  • Print ZPL labels from Node.js

    Build a ZPL string in Node.js and send it as raw base64. The agent does not render the label; the printer does.

Free plan: 100 jobs a month on one computer, no card.

Create a free accountRead the API docs
PrintBase

PrintBase connects your applications to physical printers anywhere - securely, reliably, and in real time.

Product
Receipt PrintingLabel PrintingDashboardDevicesWebhooks
Resources
DocsBlogStatusAPI ReferenceDownloadPrintBase vs PrintNodePrintNode PricingFAQ
Guides
All guidesIntegrationsPrintersCode samplesComparisonsUse casesTroubleshooting
Company
ContactSecurityPrivacy

© 2026 Aveniq Technologies OÜ. All rights reserved. PrintBase is a service of Aveniq Technologies OÜ.

PrivacyTermsRefunds