This tutorial explains the REST and ZPL preview section. While you have a template opened in template editor, you can easily check and edit the template code and copy the ZPL code that will be sent to the printer. You can also generate JSON body for REST API, which can help you in testing or using application’s endpoints.
Open the label template editor
You can use an existing template or create a new one for this tutorial. If you don’t know how to do it or you would like to learn basic information about the sizes and positioning of elements on the label, check out this this tutorial first.
To open the preview panel, open an existing label in the editor and press the REST API Access & Preview
button at the bottom of the editor.
For this tutorial, it is very important that your label contains at least one item and at least one placeholder (two or more are welcome). This will let you know both the ZPL code and the construction of the JSON object.
Prepare example label structure and content
someName
and someDescription
and set their values to The Name
and The Description
.The first section on the left side of the bottom preview panel is a preview of the current template code. By clicking the button Generate code
you will generate the current code of the label, with the possibility of editing.
Review the label code preview
Open the bottom REST API Access & Preview
panel and click the Generate code
button in the first column.
The second section of the bottom preview panel is a REST API JSON body preview
. This section allows you to view and copy example JSON body which can be used with REST API endpoint for printing.
Assuming you have created someName
and someDescription
placeholders according to the previous section on preparing a test label and set them to default values, the JSON preview section will look like this:
{
"someName": "The Name",
"someDescription": "The Description"
}
As you can see, the JSON body that should be sent to the REST printing endpoint is a simple list of placeholders’ names with values that should be substituted in place of the appropriate placeholders.
For more information on printing using the REST API, visit the relevant tutorial available on our website.
Review the REST API JSON body preview
Open the bottom REST API Access & Preview
panel and review the JSON body generated for your template. Try to change some values and/or names of placeholders. Then save the template and review the JSON again.
The last section of the bottom preview panel is a Generated ZPL preview
. ZPL is the language in which the printers get their content to print. An example of very short ZPL code presenting a label with one text field with TEST
content looks like this:
^XA
^CI28
^PON
^BY2,3,0,10
^LH0,0
^FO99,53^A0N,60,60^FH^FD_54_45_53_54^FS
^XZ
You can copy this ZPL code (and any other ZPL preview code from the application) and paste it in the online ZPL code viewer labelary.io to see the result. The result of the code in this example should represent a simple TEST
string.
The application translates the label template into ZPL and sends the generated code to the printer. ZPL code can also be sent to the printer as raw data. One of application endpoints allows this operation, redirecting the raw data to the desired printer queue.
Review the Generated ZPL preview
Open the bottom REST API Access & Preview
panel and review the generated ZPL code. Try making changes to the template, save it, and review the ZPL again.