# Attemping to store API values in tag

**URL:** <https://forum.inductiveautomation.com/t/attemping-to-store-api-values-in-tag/71652>\
**Category:** Ignition\
**Created:** [March 27, 2023, 4:05pm UTC](https://forum.inductiveautomation.com/t/attemping-to-store-api-values-in-tag/71652 "2023-03-27T16:05:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Salisbury](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thomas_salisbury/32/62046_2.png) [@Thomas\_Salisbury](https://forum.inductiveautomation.com/u/Thomas_Salisbury)\
**Post date:** [March 27, 2023, 4:05pm UTC](https://forum.inductiveautomation.com/t/attemping-to-store-api-values-in-tag/71652/1 "2023-03-27T16:05:06Z")

</div>

I am trying to expand on my API calls and store them in tags, and have a timer update them ever so often. One problem I am running into is storing the array of data i get back from the API. Example below

```auto
def getPMList(building):
	res = {}
	client = system.net.httpClient()
	response = client.get("https://api.megamation.com/clm/DL/workorder?STATUS=S&TYPE=PM&BUILDING_ID="+building, username="<>", password="<>")
	res = [
		{
			'wo_no': key['wo_no'],
			'date': key['date'],
			'building_id': key['building_id'],
			'work_request_description': key['work_request_description'],
			'type': key['type']
		}
		for key in response.json['_embedded']['WorkOrder']
	]
	system.tag.writeBlocking("maintenance/megamation/number_open_pms", len(res))
	system.tag.writeBlocking("maintenance/megamation/pmList", res) 
	return res

```

I am getting a length error on the array memory tag though.

> File "module:getPMList", line 17, in getPMList  
> ValueError: Length of values does not match length of paths.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 27, 2023, 4:17pm UTC](https://forum.inductiveautomation.com/t/attemping-to-store-api-values-in-tag/71652/2 "2023-03-27T16:17:27Z")

</div>

[`system.tag.writeBlocking`](https://docs.inductiveautomation.com/display/DOC81/system.tag.writeBlocking) expects a _list_ of paths and values to write to [1]. In your final call, you're passing a single path, but a list of values - so the function throws an error because it doesn't know how to marshal your results to the tag path provided.

[1] - There's a convenience overload that accepts a _single_ path and single value, outside of a list, to save syntax overload in simple scenarios and for training classes; that's the only reason your first call to `number_open_pms` works.

You should only issue one call to writeBlocking (also, do you _actually_ need to write this blocking, or could you write this asynchronously?

```python

def getPMList(building):
	client = system.net.httpClient()
	params = {
		"STATUS": "S",
		"TYPE": "PM",
		"BUILDING_ID": building
	}
	response = client.get("https://api.megamation.com/clm/DL/workorder", params=params, username="<>", password="<>")
	res = [
		{
			'wo_no': key['wo_no'],
			'date': key['date'],
			'building_id': key['building_id'],
			'work_request_description': key['work_request_description'],
			'type': key['type']
		}
		for key in response.json['_embedded']['WorkOrder']
	]
	system.tag.writeBlocking(
		["maintenance/megamation/number_open_pms", "maintenance/megamation/pmList"],
		[len(res), res]
	)
	return res

```

---

<div class="post-metadata">

**Author:** ![Thomas\_Salisbury](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thomas_salisbury/32/62046_2.png) [@Thomas\_Salisbury](https://forum.inductiveautomation.com/u/Thomas_Salisbury)\
**Post date:** [March 27, 2023, 4:21pm UTC](https://forum.inductiveautomation.com/t/attemping-to-store-api-values-in-tag/71652/3 "2023-03-27T16:21:31Z")

</div>

> [@paul-griffith](#):
>
> ```auto
> system.tag.writeBlocking(
> ["maintenance/megamation/number_open_pms", "maintenance/megamation/pmList"],
> [len(res), res]
> 
> ```

No it didn't need to be a blocking call. I was reading the page on "reading and writing tags" and didn't see the Asynchronous calls. Thank you again for your advice.

---

<div class="post-metadata">

**Author:** ![Thomas\_Salisbury](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thomas_salisbury/32/62046_2.png) [@Thomas\_Salisbury](https://forum.inductiveautomation.com/u/Thomas_Salisbury)\
**Post date:** [March 28, 2023, 11:43am UTC](https://forum.inductiveautomation.com/t/attemping-to-store-api-values-in-tag/71652/4 "2023-03-28T11:43:12Z")

</div>

I wanted to add that I was able to clean this up and store the data in a tag as a dataset instead of a string array as above, which will link to a perspective table directly.

```auto
def getPMList(building):
	client = system.net.httpClient()
	response = client.get("https://api.megamation.com/clm/DL/workorder?STATUS=S&TYPE=PM&BUILDING_ID="+building, username="<>", password="<>")
	data = []
	for key in response.json['_embedded']['WorkOrder']:
		data.append([key['wo_no'], key['date'], key['building_id'], key['work_request_description']])

	
	headers = ['wo_no', 'date', 'building_id', 'work_request_description']	
	listing = system.dataset.toDataSet(headers, data)
	system.tag.writeAsync(["maintenance/megamation/number_open_pms","maintenance/megamation/pmList"], [len(data), listing])

```
