Skip to end of metadata
Go to start of metadata

There is the case to send historized tag information from your Ignition Gateway to an external system over REST.

This article covers a basic example of how to retrieve tag history data and send over POST.

Basic understanding of the module should be first acquired via the Training Videos and Documentation


  1. Create a new RESTful consumer:

 


2. Input your URL destination, select POST as the Method, and JSON Data Format. 

Copy the following data structure in the JSON Body as the following steps require this data structure:


3.  The following script will read the historized tag data from the provided tag paths, transform the dataset to fit the data structure developed in the Request JSON Body, and call the web service by name:

def dataset_to_dict_list(dataset):
	"""
	Below script transforms the returned dataset to the following data structure:
	'data' [{
		't_stamp': 'Thu Nov 05 19:44:33 UTC 2020', 
		'tag_data': [
			{
				'Tag 1': 322
			}, 
			{
				'Tag 2': 282
			},
			{
				'Tag 3': 739
			}
		]
	}]
	"""
	data = []
	for row in range(dataset.getRowCount()):
		tag_data = []
		for col in range(1,dataset.getColumnCount()):
			tag_data.append({dataset.getColumnName(col):dataset.getValueAt(row,col)})
		data.append({dataset.getColumnName(0):dataset.getValueAt(row,0), 'tag_data':tag_data})
	return data
	
endTime = system.date.now()
startTime = system.date.addHours(endTime,-1)

#all the tags to send via POST request
paths = [
'[default]History/Tag 1',
'[default]History/Tag 2',
'[default]History/Tag 3',
'[default]History/Tag 4',
'[default]History/Tag 5']

#https://docs.inductiveautomation.com/display/DOC80/system.tag.queryTagHistory
dataset = system.tag.queryTagHistory(paths=paths, startDate=startTime, endDate=endTime, aggregationMode="LastValue", returnFormat='Wide', intervalMinutes =5)

data = dataset_to_dict_list(dataset)

#"Post" is the name of the path to the web service configuration
system.ws.runWebService("Post",
{ # Body Variables:
  'data': system.util.jsonEncode(data)
})



*The success of the POST request can be tested on the same server by creating a RESTful Provider, uncommenting the template script, and logging the Request Body received:

  • No labels