print (POST)
{server}/api/v1/printDirect/print
Description
(requires v2.9 or later)
Print string content such as ZPL commands directly to printer.
See also the OpenAPI (Swagger) definition.
Applies to:
- ScriptX.Services for Cloud - the API is implemented for illiustration purpose but no print occurs - an error is returned.
- ScriptX.Services for On-Premise Devices (Authorisation header is ignored)
- ScriptX.Services for Windows PC
Request parameters
PrintDirectDescription {
contentType (integer, required): 1 = url, 8 = string,
content (string, required),
printerName (string, optional)
}
PrintDirectDescription:
- contentType (integer, required)
-
Defines the type of content to be printed.
1 (Url - the content parameter will contain the URL of the content to be printed)
8 (String - the content parameter will contain the string to print) - content (string, required)
- The content to be printed, corresponding to contentType value above. Either a URL or a string.
- printerName (string, optional)
- Name of the printer/device available to the ScriptX.Services device (Windows PC/Windows Server) to send the content to directly. If not specified then the ScriptX.Services device default printer is used.
Response model
Print {
status (integer, optional): 3 = SoftError, 4 = Ok,
jobIdentifier (string, optional),
message (string, optional)
}
Print:
- status (integer, optional)
- Code indicating initial status of the print. 3 (Soft error), 4 (Ok - printed and complete)
- jobIdentifier (string, optional)
- Direct printing is not asynchronous at the server, no job is queued and so no job identifier is returned. The value is always an empty string.
- message
- Returns error message if status is 3, otherwise returns empty string.
Example usage
async function sendPrintRequest() {
const requestData = {
contentType: 8,
content: "^XA^FO50,50^ADN,36,20^FDScriptX RawPrinting^FS^FO50,100^ADN,36,20^FDMead & Company^FS^XZ",
printerName: "ZDesigner LP 2844-Z"
};
const headers = new Headers({
"Content-Type": "application/json",
"Authorization": "Basic " + btoa("13598d2f-8724-467b-ae64-6e53e9e9f644" + ":")
});
try {
const response = await fetch("https://scriptxservices.meadroid.com/api/v1/printDirect/print", {
method: "POST",
headers: headers,
body: JSON.stringify(requestData)
});
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
if (data.status === 3) {
// handle returned error.
console.error('Error:', data.message);
} else {
// handle success
console.log('Print job status:', data.status);
}
} catch (error) {
console.error('There has been a problem with your fetch operation:', error);
}
}