Actions API

软件教程 admin 2024-04-24 08:51 73 0

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:


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


操作

命令

描述

Submit a Script to Run

提交要运行的脚本。

Get a List of Submitted Scripts

获取提交给服务器的脚本列表。

Update Script Properties

修改脚本的“KeepStatus”或“Command”属性。

获取脚本的运行状态

获取脚本的运行状态。

Get All Variable Values

获取所有变量的值。

Get the Value of the Specified Variable

Gets the value of the specified variable.


使用 POST 命令时,可以指示 BarTender 执行各种操作。您可以在 POST 命令中使用参数来指定等待操作完成的时间或要接收的消息。提交 POST 命令后,服务器会返回响应。此响应包含指示是否接受脚本的 HTTP 状态代码。成功的响应还包含脚本的 ID,您需要使用它来运行 PATCH 和 GET 命令。默认情况下,操作完成运行后,状态、消息和变量等操作数据会在服务器中存储 60 分钟,但您可以根据需要修改此设置和其他参数。

发布的操作脚本可以是 YAML 或 JSON 格式。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>

 


评论区