REST API printing endpoints are a powerful tool that enables application integration with any data source capable of sending a simple request to a specified address in the network. Thanks to this, JustLabel can work with any client’s system, regardless of the language of its implementation and the architecture used.
The application launched in the server or desktop version provides public API enabling integration with any client system. In short, the printing process looks like this:
Please note that this solution is completely independent of client and server operating systems, programming languages and physical location of devices. The only requirement for printing is the ability to connect all these devices with the ethernet network.
You can access the REST API documentation on the documentation page and directly on the local machine or server machine running the application. To view the documentation page provided by the application, you need to know the host address and the port number of the running JustLabel instance. For the desktop version, this will be localhost:5987
. In any web browser, visit the mentioned address with the additional path /swagger-ui/index.html
. The final documentation address for the desktop version should look like this:
http://localhost:5987/swagger-ui/index.html
In the examples of this tutorial, we assume the desktop version and use the presented address. If the application is running in the server version, in the above address, localhost:5987
should be replaced with the server’s host name or IP address and appropriate port number.
After visiting this page, a content similar to the one presented below should be displayed. There are descriptions of REST API endpoints and data transfer objects (DTO).
Remember, you can test the endpoints directly from this page. Just use the Try it out
button on desired endpoint, fill in all the necessary data and press Execute
to send the request.
This tutorial is based on highly personalized settings. The user can use the desktop or server version of the program, he can have any names of printers and print queues, he can have any names of labels as well as any names of placeholders. Therefore, we need to prepare a set of data on which we will build the following examples. Below we present a set of exemplary data along with a description of individual elements. This will allow you to easily transfer the logic of the examples to real customer use cases.
localhost
5987
testPrinter
pq_testPrinter
testTemplate
namePlaceholder
= “The Name“descriptionPlaceholder
= “The Description“The simple print
endpoint allows user to print one copy of a label with specified template and printer queue. The endpoint path is
/simple-print/{printerQueueName}
To print using this endpoint, there are some parts of a request that have to be provided:
printerQueueName
path parameter – print queue name to tell the program which printer you want to print to. Our example: pq_testPrinter
templateName
query parameter – the name of the template, which should be printed. Our example: testTemplate
request body
– a JSON request body object containing the template’s placeholders list with the name and value pairs, wrapped in brackets: [ ]
. Our example placeholders are namePlaceholder
and descriptionPlaceholder
Finally, the simple-print
request for our example data should look like this:
URL
http://localhost:5987/simple-print/pq_testPrinter?templateName=testTemplate
JSON
[
{
"namePlaceholder": "The Name",
"descriptionPlaceholder": "The Description",
},
]
The print
endpoint allows user to print multiple copies of a label using template or raw data. In this section we will discuss the template version. The endpoint path is
/print/{printerQueueName}
To print using this endpoint, there are some parts of a request that have to be provided:
printerQueueName
path parameter – print queue name to tell the program which printer you want to print to. Our example: pq_testPrinter
request body
– a JSON request body containing the necessary template-print information. Request body schema for the template print version looks like this:{
"template": {
"name": "string",
"options": [
{
"numberOfCopies": 0,
"placeholderValues": {
"additionalProp1": "string",
"additionalProp2": "string",
"additionalProp3": "string"
}
}
]
}
}
As you can see, the JSON body is a bit more complicated in this version than in simple-print
, but you will easily understand everything by looking at the example supplemented with our sample data.
templateName
has been included here in the JSON body as a field of the template
object and has the short name name
. In our case, it will take the value of testTemplate
numberOfCopies
which simply indicates how many copies of the label you want to printplaceholderValues
object you can specify the names and values of template’s placeholders. In our case, the namePlaceholder
and descriptionPlaceholder
will be includedThe final version of print
endpoint request looks like this:
URL
http://localhost:5987/print/pq_testPrinter
JSON
{
"template": {
"name": "testTemplate",
"options": [
{
"numberOfCopies": 1,
"placeholderValues": {
"namePlaceholder": "The Name",
"descriptionPlaceholder": "The Description"
}
}
]
}
}
The print
endpoint described in previous section allows also the raw data print. It means, the application would not modify the given data but it will send it directly to the printer. Following logic from the previous example, you have to point the printer using the path parameter, so the URL doesn’t change and our example printer queue is pq_testPrinter
:
URL
http://localhost:5987/print/pq_testPrinter
In the JSON body however, you don’t use the template
object. You should use raw
object instead and put the raw ZPL code as the value of the code
field. We will use the ZPL code for an empty label just to demonstrate the example JSON body with raw code object.
JSON
{
"raw": [
{
"numberOfCopies": 1,
"code": "^XA
^CI28
^PON
^BY2,3,0,10
^LH0,0
^FO10,10^A0N,30,30^FH^FD_53_6F_6D_65_20^FS
^XZ"
}
]
}
Sometimes it is necessary to prevent unwanted print requests. Imagine a situation that you have developed an application that makes printouts using the REST API, but a new version has already been created and you want to deny print permission to all previously released programs or you just want to prevent any unauthorized printouts of any other reason.
You can achieve this simply by securing the printer queue using the API Key. The description on how to do this can be found in this tutorial.
If your print queue is already secured by API Key, printouts without an authorization key will be rejected. If print authorization is required, the value of the API Key should be appended to each print request as one in the header named X-API-Key