API de Acciones

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. Puede copiar cada comando en su entorno de desarrollo y personalizarlo según sus necesidades.

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/

Acción

Comando

Descripción

Submit a Script to Run

Envía un archivo de comandos para que se ejecute.

Get a List of Submitted Scripts

Obtiene una lista de archivos de comando enviados al servidor.

Update Script Properties

Modifica las propiedades "KeepStatus" o "Command" del archivo de comando.

Get a Script's Running Status

Obtiene el estado de ejecución de un archivo de comando.

Get All Variable Values

Obtiene los valores de todas las variables.

Get the Value of the Specified Variable

Gets the value of the specified variable.

Cuando utiliza un comando POST, puede ordenar a BarTender que realice varias acciones. Puede utilizar los parámetros del comando POST para especificar cuánto tiempo debe esperar a que se completen las acciones o qué mensajes desea recibir. Después de enviar el comando POST, el servidor devuelve una respuesta. Esta respuesta contiene un código de estado HTTP que indica si se ha aceptado el archivo de comando. Las respuestas exitosas también incluyen el ID del archivo de comando, que necesita para utilizar los comandos PATCH y GET. Por defecto, una vez que las acciones terminan de ejecutarse, los datos de la acción, como el estado, los mensajes y las variables, se almacenan en el servidor durante 60 minutos, pero puede modificar esta configuración y otros parámetros según sea necesario.

Los archivos de comando de acción que publique pueden estar en formato YAML o JSON. El documento de referencia YAML que se incluye con el archivo de instalación de BarTender proporciona detalles completos sobre las propiedades específicas de cada acción y describe cómo combinar acciones en grupos y crear matrices de acciones para enviarlas como un solo archivo de comando al servidor. For more information about how to access the YAML reference, refer to Available Actions in the Actions API.

Puede utilizar cualquiera de los diversos métodos para enviar sus archivos de comando al servidor, incluidos los comandos cURL, los archivos de comando PowerShell y JavaScript, como se muestra en los siguientes ejemplos de código.

Ejemplo de un comando cURL que imprime un documento BarTender

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

Ejemplo de un archivo de comando PowerShell que imprime todos los archivos *.btw en una carpeta especifica

param (

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

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

[string]$out_pdf_filename = "PrintByPrintBTWAction.pdf"

)

 

$template = "

PrintBTWAction:

Documento: {0}

Impresora: 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"

}

Ejemplo de un archivo de comando JavaScript que imprime un documento BarTender

<!DOCTYPE html>

<html>

<head>

<script>

const actionScript = '\

{\

"PrintBTWAction": {\

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

"Printer": "PDF",\

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

"PrintToFileFileName": "PrintByPrintBTWAction.pdf",\

"SaveAfterPrint": false\

}\

}\

';

 

función sendByFetch()

{

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

 

fetch(url,

{

método: "POST",

cuerpo: actionScript,

credenciales: 'include'

})

.then(function(response) {

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

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

{

return response.json();

}

throw new TypeError("¡Uy, no tenemos 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>