Print Portal REST API
Introduction
In BarTender 2021 and later, programmers can now interact with Print Portal through a comprehensive set of REST APIs. You can perform most operations via our REST API to authenticate users, list existing folders, labels, and printers, and printing labels by issuing queries and retrieving results as JSON.
This article is intended to provide a brief overview of the Print Portal REST APIs. It will walk you through the Rest API Authentication method and show how to use swagger tool for API Testing.
Endpoints and Methods
The Print Portal REST API is designed around RESTful principles, and as such, it supports the two most common HTTP methods: GET
and POST
.
The Print Portal REST API provides access to the resources through Endpoint URIs. All the Print Portal API endpoints have the following base URL:
{Print Portal Base URL}/BarTender
A specific endpoint must be used when submitting REST API requests. Print Portal API V1 consists of 4 endpoints which are grouped as follows:
Table 1-1 Print Portal REST API Endpoints and Methods.
Endpoint |
HTTP Method |
Description and Example |
Login Required |
Authentication |
POST |
Authenticate with your username and password for future requests /api/v1/Authenticate
|
Yes |
AutomatedPrint |
POST |
Performs an automated print job to the specified file path inside a given library. /api/v1/print
|
No |
Library |
GET |
Returns the available libraries. /api/v1/libraries/{id}
|
NO |
Printers |
GET |
Returns the available printers. /api/v1/printers/{printerName}
|
NO |
Authentication
When authentication is enabled, before access to Print Portal resources can be acquired, a request must originate from an authenticated user. If successful, a token will be returned.
To generate an authentication token, send a POST
request to
{Print Portal Base URL}/BarTender/api/v1/Authenticate
with the following input body:
{
"userName": "UserName@Domain",
"password": "Password"
}
this will return a JSON user structure which contains a token
property:
{
"success": true,
"token": "string",
"expires_in": 0
}
When calling REST API endpoints, all future requests need to have an Authorization
header with the following format:
Authorization
: Bearer <TokenString>
Getting Started with Swagger UI
Print Portal also contains a REST API specification system called swagger. Swagger UI allows you to visualize and interact with the API’s resources without having any of the implementation logic in place. Think of swagger as a REST API Help System that provides an explanation, an execution environment for testing requests, and explanations for each function.
Swagger can be accessed by typing in swagger after the BarTender in the Print Portal Base URL, example:
{Print Portal Base URL}/BarTender/swagger/
The swagger presentation is divided into two halves, and this is important to know to find the right information. The top section contains API function explanations and the ability to test execute API requests. The bottom section, titled “Models” provides an explanation for each function and its requirements.
As already mentioned, Swagger UI offers a valuable time-saving features to make testing an API on deployment straightforward and painless. For example, for testing Authentication, expand the corresponding top item to view the authentication requirements.
Select the button, “Try it out” and add your username and password with the following format:
Then select the big blue Execute button:
Which will then return success (when PrintPortal authentication is enabled, and the correct username and password are submitted) and the authentication token to use for future REST API calls.
More Information
For additional information to help you get started with automating Print Portal, you can refer to the Print
Portal help system.