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. Sie können die einzelnen Befehle in Ihre Entwicklungsumgebung kopieren und nach Bedarf anpassen.

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/

Aktion

Befehl

Beschreibung

Submit a Script to Run

Übermittelt ein auszuführendes Skript.

Get a List of Submitted Scripts

Ruft eine Liste der Skripte ab, die an den Server übermittelt wurden.

Update Script Properties

Ändert die Eigenschaften „KeepStatus“ oder „Command“ des Skripts.

Get a Script's Running Status

Ruft den Ausführungsstatus eines Skripts ab.

Get All Variable Values

Ruft die Werte aller Variablen ab.

Get the Value of the Specified Variable

Gets the value of the specified variable.

Mit einem POST-Befehl können Sie BarTender anweisen, verschiedene Aktionen auszuführen. Sie können mit den Parametern im POST-Befehl angeben, wie lange Sie auf den Abschluss der Aktionen warten oder welche Nachrichten Sie erhalten möchten. Nachdem Sie den POST-Befehl übermittelt haben, gibt der Server eine Antwort zurück. Diese Antwort enthält einen HTTP-Statuscode, der anzeigt, ob das Skript angenommen wurde. Erfolgreiche Antworten enthalten außerdem die Skript-ID, die Sie für die PATCH- und GET-Befehle benötigen. Nach dem Abschluss der Aktionen werden Aktionsdaten wie Status, Nachrichten und Variablen standardmäßig 60 Minuten lang auf dem Server gespeichert. Sie können diese Einstellung und andere Parameter aber nach Bedarf anpassen.

Sie können Aktionsskripte im YAML- oder JSON-Format verwenden. Das YAML-Referenzdokument in der BarTender-Installationsdatei enthält alle Details zu den spezifischen Eigenschaften der einzelnen Aktionen sowie eine Beschreibung, wie Sie Aktionen in Gruppen zusammenfassen und Aktionsfolgen erstellen können, die als ein Skript an den Server gesendet werden. For more information about how to access the YAML reference, refer to Available Actions in the Actions API.

Sie können eine beliebige Methode verwenden, um Ihre Skripte an den Server zu senden, einschließlich cURL-Befehle, PowerShell-Skripte und JavaScript. Sehen Sie sich zum besseren Verständnis die folgenden Codebeispiele an.

Beispiel eines cURL-Befehls zum Drucken eines BarTender-Dokuments

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\" } }"

Beispiel eines PowerShell-Skripts zum Drucken aller *.btw-Dateien in einem angegebenen Ordner

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"

}

Beispiel eines JavaScript-Skript zum Drucken eines BarTender-Dokuments

<!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>