postDictionary is being compiled from two separate lists using zip in a for loop.
Result is:
{‘Barcode1’: ‘0190076338816517320100078911220322213609008158’,
‘Barcode2’: ‘0190076338816517320100079111220322213609008157’, }
First question, is there a way to make the Key the same and treat each as a separate key/value pair?
Ie. {“Barcode”: “013…”} , {“Barcode”: “014…”}
I setup the Keys list to take the string “Barcode” + str(index) for the number of cases generated. (the index runs in a range of 1-51, unless the barcode is == “99999”) When I send it to the API it’s rejected because of the attached number. ie. “Barcode1” instead of “Barcode”.
API is looking for this structure
{
"Pallet": {
"PalletNumber": "string",
"Cases": [
{
"Barcode": "string"
}
]
}
}
This works when posting through the API web interface
{
"Barcode": "string"
}
,
{
"Barcode": "string"
}
Scripting to get everything in place
if palletStatus == "OK":
palletFormat = {"Pallet": {"PalletNumber": apiPalletNumber, "Cases": [postDictionary]}}
palletFormatJsonEncoded = system.util.jsonEncode(palletFormat)
This is after Json encoding;
{
"Pallet":{
"PalletNumber":"example 20 digits",
"Cases": [{"Barcode1":"example 46 digits",
"Barcode3":"example 46 digits",
"Barcode2":"example 46 digits",
"Barcode4":"example 46 digits"
}]
}
}
Any help would be greatly appreciated and sorry if this is a bit incoherent. If any clarification is needed, please let me know. The version of Ignition is 7.9 and all of this is being tested through the designers script console at the moment, but will later be added as a gateway script that’s triggered by a plc condition. Initially, I did create this using a for loop and httpPost for each iteration, but instead of a possible 50 different messages being sent at a time we are trying for 1 message with 50 records.