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 秒間保存されますが、この設定とその他のパラメータは必要に応じて変更できます。
POST に使用できる操作スクリプトは YAML または JSON 形式です。BarTender のインストールファイルに含まれている YAML の参照ドキュメントには、各操作の特定のプロパティに関する完全な詳細が含まれ、複数の操作をグループに組み合わせて、サーバーに 1 つのスクリプトとして送信する操作の配列を作成する方法が記載されています。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>