using the new REST API in 2022.. multiple labels
One request I've heard repeated in the past is the ability to print more than one label from a web services request. Well now with 2022 you can ! There's probably more than one way, but here is one I have working in this test script:
const fetch = require('node-fetch');
const base64 = require('base-64');
const authUser = 'localbt';
const authPass = '<password here>';
const authString = 'Basic ' + base64.encode(authUser + ':' + authPass);
const btAPIBase = 'http://localhost:5159/api/actions';
const btAPIOptions = {
Wait: '30s',
MessageCount: '200',
MessageSeverity: 'Info'
};
const btAPI = btAPIBase + '?' + Object.keys(btAPIOptions).map(key => key + '=' + btAPIOptions[key]).join('&');const btPrinter = 'wilkins-zebra2';
const btwFile = 'C:/label_files/gs1-128a.btw';
const actionScript = JSON.stringify({
ActionGroup: {
Actions: [
{
PrintBTWAction: {
Document: btwFile,
Printer: btPrinter,
SaveAfterPrint: false,
NamedDataSources: {
ship_addressee: 'ABC Company',
ship_address1: '1 Main St.'
}
}
},
{
PrintBTWAction: {
Document: btwFile,
Printer: btPrinter,
SaveAfterPrint: false,
NamedDataSources: {
ship_addressee: 'XYZ Company',
ship_address1: '1 High St.'
}
}
}
]
}
}, null, 4);
console.log('sending', actionScript);
sendByFetch();
function sendByFetch() {
url = btAPI,
fetch(url,
{
method: 'POST',
headers: {
'Authorization': authString,
'Content-Type': 'application/json'
},
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) {
console.log('response: ',json);
})
.catch(function (error) {
console.log(error);
});
}
-
Permanently deleted user
★ BarTender Hero ★
My first question is, what is the best practice for printing many labels with the same BTW file but different data on each ? The fields on the label format are filled from named data sources.
My second question is how big can the ActionScript (in the POST body) be ? Can it be 1MB ?
0 -
Nicholas van Wyngaard
★ BarTender Hero ★
Agree with Jeff. Is it possible to add multiple sets of named data sources in a single post?
0 -
Michał Pasz
★ BarTender Hero ★
Hi,
I 've wonder if there is any possibility to add multiple named data source in single post ?
0 -
Peter Thane
★ BarTender Hero ★
As far as I am aware you cant print multiple named data sources from a single post.
Have you seen this?
0
Iniciar sesión para dejar un comentario.
Comentarios
4 comentarios