Confusion with system.tag.browse()

I’m trying to understand how to use system.tag.browse(), using this example from the docs

# This script has created a browseTags function which can be called with a Tag path and filter.
# The function will recursively find all items under that path by going into folders and UDT Instances.
# This example gives the initial path of '[default]', meaning it will find every item in the Tag Provider called default.
results = system.tag.browse("[default]", {"tagType":"UdtInstance", "recursive":True}).results
for result in results:
        print result['fullPath']

The docs say that ‘fullPath’ represents

A fully qualified Tag path to the node, including the name of the node.

I inferred this to mean the path name of the tag as seen in the list of tags including folders etc that they are in. However when I run this from a GW context, I simply get a list of


With no folders shown in the results. So question #1 is how do I get what I think should be a path that includes folders and subfolders etc?

The second question is that this code only lists instances of UDTs (which is what I want), but how do I get it to tell me what the UDT type is? The docs seem confused about what key I should use to do this. It suggests that the key of ‘tagType’ is used to access both the type of node, as well as the base UDT type.


I discovered by dumping an entire tag that the UDT type is accessed by the ‘typeId’ key (which is actually referenced in the ‘filter’ sections of the docs).

There’s a bug currently when using recursive, where the full path isn’t returned only the tag name is returned. You need to use the example further down, or there’s an example function on the forum. I’ll get back to you a little later

Now that I know there is a bug with ‘recursive’ I can work around it. I only really need to scan the tags from one particular folder, but I was hoping to be robust enough that if the folder was moved that my solution would still work.

This is what I use for tag browse:

def browseTags(path, filter={}, recursive=False, ret=None):
	if ret==None: ret=[]
	# First, browse for anything that can have children (Folders and UDTs, generally)
	if str(path).find("[") == -1:
		path = '[default]' + str(path)
	if recursive:
		results = system.tag.browse(path)
		if results.getResults() is not None:
			for branch in results.getResults():    
				if branch['hasChildren']:
					# If something has a child node, then call this function again so we can search deeper.
					# Include the filter, so newer instances of this call will have the same filter.
					ret = browseTags(path=branch['fullPath'], filter=filter, recursive=recursive,ret=ret)
	# Call this function again at the current path, but apply the filter.
	results = system.tag.browse(path, filter)
	if results.getResults() is not None:
		for result in results.getResults():
	return ret