REST API based integration with JSON Label Data
We are trying to send a label job to BarTender from a remote web server.
The payload to a BTIN integration endpoint is as follows:
{ "printer": "PDF", "template": "P:\\RemoteBarTenderServer\\SimpleSampleLabelTemplate.btw", "copies": "1", "labels": "[{\"Barcode\":\"0448c96b-063e-41a1-8677-6e25becf5bcf\",\"Sample ID\":\"QCS_0253\"},{\"Barcode\":\"9d71cfec-7aa3-426d-b151-39aabf494f16\",\"Sample ID\":\"QCS_0252\"}]" }
We are setting the Printer using the "printer" variable.
We are setting the template path dynamically using the "template" variable.
We are setting the # of copies via the "copies" variable.
I believe we need to use a "Database Override" to push the "labels" JSON array across from the BTIN integration to the BTW template document.
We added an example JSON database to the BTW template document, but we are still getting blank or embedded example data from the label, rather than multiple single labels or an Avery sheet worth of labels.
Are there more detailed instructions for passing multiple labels worth of data using a JSON payload as above??
-
Rajath Muthyala
★ BarTender Hero ★
Hi Justin,
Based on the provided JSON payload, it seems there was an issue with the formatting of the "labels" array. I encountered a similar problem when attempting to add the JSON data to my template as embedded data.
Upon closer inspection, it appears that the backslashes before the quotes in the "labels" string were causing the JSON validation to fail. The correct format for the "labels" array should be without the escape characters:
[ {"Barcode":"0448c96b-063e-41a1-8677-6e25becf5bcf","Sample ID":"QCS_0253"}, {"Barcode":"9d71cfec-7aa3-426d-b151-39aabf494f16","Sample ID":"QCS_0252"} ]
After removing the backslashes, the JSON payload worked seamlessly with the BarTender template, allowing it to load up multiple records successfully. I recommend giving this revised format a try in your integration. Let me know how you go.
0 -
Gshreenivasan
★ BarTender Hero ★
It's not clear if you answered Justin's question. I think there is a lack of samples in sending arrays of json data in the payload to the REST API (There is some documentation for the XML version). Can someone please produce a successful "database" binding using a json array posted to the RESP API end point?
1 -
Rajath Muthyala
★ BarTender Hero ★
You're right, I don't think I answered the question. See if this helps.
Yes, to override the data in BTIN you need to do database overrides.
You said that you are either getting blank or embedded sample data when triggered. This could be happening if in the BTIN print actions database overrides you have changed the "Database to override" to a specific name or variable instead of the default "(The default database)"
If you did, either delete the database override and add it again, or you can change the name of the embedded sample data file in the .btw file such that they match.
With regards to an example to send and print arrays using Post rest action, I choose to do it using BTIN rather than the Rest API, but it should be almost the same. Here is an example.
{
"BTDRFile": "\\\\N01\\Shared\\Bartender\\Bartender Integrations\\Testing.btw",
"Printer": "Intermec EasyCoder PX6i (300 dpi)",
"Copies": "1",
"Trigger": "5",
"Array": [{
"Text1": "Hello World",
"Text2": "Text 1"
},
{
"Text1": "Hello World 2",
"Text2": "Text 2"
}]
}This example produces 2 labels with different data. Text1 and Text2 are then connected to named data sources in the .btw file. Let me know if you have any questions.
0 -
Gshreenivasan
★ BarTender Hero ★
I am trying to POST to the REST API, here is my json. What is wrong or should be different? My database in the btw file is called "Aircrafts" and has a table of embedded data called "JSON" that I want to override using the following payload. Thanks for any help you can offer.{"libraryID":"8a42c7ca-2d53-4316-9cd7-4d638bf4fa2b","relativePath":"Giri/Airplanes2.btw","printer":"PDF","copies":1, "Recordset": {"Name": "Aircrafts","embeddedData":[{"Model":"173","Manufacturer":"Cessna","Years":1932},{"Model":"StagsgerWing","Manufacturer":"Beechcraft","Years":1256},{"Model":"Kincg Air","Manufacturer":"Beechcraft", "Years":1264},{"Model":"1820","Manufacturer":"Cessna", "Years":2953},{"Model":"1714","Manufacturer":"Beechcraft", "Years":1322}]}}0 -
Rajath Muthyala
★ BarTender Hero ★
Hi Gshreenivasan,
I am not well-versed in the REST API, I did find this post by another user. Link
You can also check out Bartender YAML reference for the same. Link
I found integration builder is much more simpler to work from and gives much more flexibility. Is there a reason you would prefer using RestAPI instead of BTIN?
0
Vous devez vous connecter pour laisser un commentaire.
Commentaires
5 commentaires