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.在 ReDoc 中,您可以展開左側導覽窗格中的項目並捲動尋找所需的指令。您可以將每個指令複製到您的開發環境中,然後視需要對其進行自訂。 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: |
動作 |
指令 |
描述 |
---|---|---|
|
提交要執行的指令碼。 |
|
|
取得提交給伺服器的指令碼清單。 |
|
|
修改指令碼的 "KeepStatus" 或 "Command" 屬性。 |
|
|
取得指令碼的執行狀態。 |
|
|
取得所有變數的值。 |
|
|
Gets the value of the specified variable. |
使用 POST 指令時,您可以指示 BarTender 執行各種動作。您可以在 POST 指令中使用參數來指定等待動作完成的時間或要接收的訊息。提交 POST 指令後,伺服器會傳回回應。此回應包含指出是否接受指令碼的 HTTP 狀態碼。成功的回應還包含執行 PATCH 和 GET 指令時所需的指令碼 ID。依預設,動作執行完成後,狀態、訊息和變數等動作資料會在伺服器中儲存 60 分鐘,但您可以視需要修改此設定和其他參數。
Action scripts that you post can be in YAML or JSON format.BarTender 安裝檔案中包含的 YAML 參考文件提供了有關每個動作的特定屬性的完整詳細資訊,並說明如何將動作組合成群組,以及建立要作為一個指令碼傳送至伺服器的動作陣列。For more information about how to access the YAML reference, refer to Available Actions in the Actions API.
您可以使用多種方法中的任何一種,將指令碼傳送至伺服器,其中包括 cURL 指令、PowerShell 指令碼和 JavaScript,如下列程式碼範例所示。
列印 BarTender 文件的 cURL 指令範例
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\" } }"
列印指定資料夾中所有 *.btw 檔案的 PowerShell 指令碼範例
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"
}
列印 BarTender 文件的 JavaScript 指令碼範例
<!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>