Actions API

The Actions API provides REST endpoints that you can use to run a variety of actions in YAML or JSON format or in an existing legacy BTXML script, and manage the scripts and variables related to those actions.

The actions that you can run by using the Actions API include many of the same actions that you can run in BarTender Designer, Integration Builder, and Process Builder. For a list of the actions supported by the Actions API, see Available Actions in the Actions API.

For more information, you can view the API reference by using ReDoc. In ReDoc, you can expand the items in the left navigation pane and then scroll to find the commands that you want. You can copy each command to your development environment and customize it as needed.

To view the API reference in ReDoc, in the browser address bar, enter the following URL, and substitute "localhost" with the name or IP address of the computer that is running BarTender:

http://localhost:5159/api/actions/reference/

Action

Command

Description

Submit a Script to Run

Submits a script to run.

Get a List of Submitted Scripts

Gets a list of scripts that were submitted to the server.

Update Script Properties

Modifies the script's "KeepStatus" or "Command" properties.

Get a Script's Running Status

Gets a script's running status.

Get All Variable Values

Gets the values of all variables.

Get the Value of the Specified Variable

Gets the value of the specified variable.

When you use a POST command, you can instruct BarTender to perform various actions. You can use the parameters in the POST command to specify how long to wait for the actions to complete or what messages you want to receive. After you submit the POST command, the server returns a response. This response contains an HTTP status code that indicates whether the script was accepted. Successful responses also include the script's ID, which you need to use the PATCH and GET commands. By default, after the actions finish running, action data such as status, messages, and variables are stored in the server for 60 minutes, but you can modify this setting and other parameters as needed.

Action scripts that you post can be in YAML or JSON format. The YAML reference document that is included with the BarTender installation file provides complete details about the specific properties for each action and describes how to combine actions into groups and create arrays of actions to be sent as one script to the server. For more information about how to access the YAML reference, refer to Available Actions in the Actions API.

You can use any one of several methods to send your scripts to the server, including cURL commands, PowerShell scripts, and JavaScript, as shown in the following code samples.

Example of a cURL command that prints a BarTender document

c:\Windows\System32\curl.exe -u : --negotiate "http://localhost:5159/api/actions?Wait=30s&MessageCount=200&MessageSeverity=Info" -X POST -H "Content-Type: application/json" -d "{ \"PrintBTWAction\" : { \"DocumentFile\": \"D:\\Temp\\Sample.btw\" } }"

Example of a PowerShell script that prints all the *.btw files in a specified folder

param (

[string]$btw_folder = "C:\samples",

[string]$out_pdf_folder = "c:\samples\out",

[string]$out_pdf_filename = "PrintByPrintBTWAction.pdf"

)

 

$template = "

PrintBTWAction:

Document: {0}

Printer: PDF

PrintToFileFolder: $out_pdf_folder

PrintToFileFileName: $out_pdf_filename

SaveAfterPrint: false

"

 

$files = @(Get-ChildItem ($btw_folder + "\*.btw"))

foreach ($file in $files)

{

$script = ($template -f $file)

Write-Host $script

c:\windows\system32\curl -u : --negotiate "http://localhost:5159/api/actions?Wait=30s&MessageCount=200&MessageSeverity=Info" -X POST -H "Content-Type: text/vnd.yaml" -d "$script"

}

Example of a JavaScript script that prints a BarTender document

<!DOCTYPE html>

<html>

<head>

<script>

const actionScript = '\

{\

"PrintBTWAction": {\

"Document": "C:/Samples/Sample.btw",\

"Printer": "PDF",\

"PrintToFileFolder": "c:/samples/out",\

"PrintToFileFileName": "PrintByPrintBTWAction.pdf",\

"SaveAfterPrint": false\

}\

}\

';

 

function sendByFetch()

{

url = "http://localhost:5159/api/actions?Wait=30s&MessageCount=200&MessageSeverity=Info"

 

fetch(url,

{

method: "POST",

body: actionScript,

credentials: 'include'

})

.then(function(response) {

var contentType = response.headers.get("content-type");

if(contentType && contentType.includes("application/json"))

{

return response.json();

}

throw new TypeError("Oops, we haven't got JSON!");

})

.then(function(json)

{

document.getElementById("responseOfFetch").innerHTML += ("<p>" + JSON.stringify(json) + "</p>")

})

.catch(function(error)

{

console.log(error);

document.getElementById("responseOfFetch").innerHTML += ("<p>" + error + "</p>")

});

}

</script>

</head>

<body>

 

<h2>Print via REST API</h2>

 

<button type="button" onclick="sendByFetch()">Send Print Request</button>

<p id="responseOfFetch"></p>

<br/>

 

</body>

</html>