Getting Perspective Project list from gateway

Hello Team, I have a query on, is there any possibility to get the perspective project list from the gateway, I need the list of Perspective projects alone. I searched the forum, I have found some information’s, but most of them were dead end. Does someone have any idea about this.

There’s a function you can call

https://docs.inductiveautomation.com/display/DOC81/system.project.getProjectNames

If you just need possible Perspective projects, you can make an HTTP request against http://$gatewayAddress/data/perspective/runnable-projects - the response is a simple JSON structure.

2 Likes

Oh, I missed that requirement. Oops. That’s useful to know!

1 Like

Thank you very much, This is what I’m expecting, one more doubt how to extract the contents, I found some script w.r.t vision projects in this forum itself , I will provide the script below, something like that is possible for perspective to extract the contents.

def getProjects():
import urllib2
from xml.etree import ElementTree as ET
projects_xml = urllib2.urlopen(‘http://10.1.1.81:8088/main/system/projectlist’).read()
projects = ET.fromstring( projects_xml ).findall(‘client’)
project_names = tuple( ( project.get(‘name’), project.find(‘title’).text )
for project in projects )
return project_names

Please share your valuable thoughts.

Thank you guys I found it, But anyway please let me know if you have some suggestion’s in that 2nd question which I had mentioned @PGriffith @nminchin.

Cool, this is what I’m searching for these days. Thank you. one more thing to @PGriffith @nminchin @Prahil_S_Kumar1 ,Do u have any document/manual
http://$gatewayAddress/data/perspective/runnable-projects for this, how we can get these info.
also do u have something similar like the json format for vision also.??

I don’t know, I found an xml for getting the details from the vision. If your requirement is full projectlist that can utilized by Projectnames.
For other queries may be @PGriffith and @nminchin can help you.

system.net.httpClient natively 'understands' JSON format, so the implementation is extremely simple:

def getPerspectiveProjects():
	response = system.net.httpClient().get("http://localhost:8088/data/perspective/runnable-projects")
	return [project["name"] for project in response.json]

print getPerspectiveProjects()

If you're in the Vision client scope, you can use system.util.getGatewayAddress to get the correct address to fill in for the request. If you're in a Perspective session or other gateway context already, then you can probably just hardcode the port the gateway is using.

No. This is considered an "implementation detail" - it could change between Ignition versions. If you're doing something outside of the first-party system functions, you are generally expected to be able to deal with problems on your own.
In this particular case, it's fairly unlikely we change this route anytime soon, so it's probably safe to rely upon. I would recommend implementing your own getPerspectiveProjects function (as I did above) in the project library and always using that; that way, if the logic for retrieving these projects does change, you can make the change in only one place.

As for discovering this info yourself: You can just watch the network traffic (via the browser's development tools) when you navigate to the 'Perspective Session Launcher' on the gateway homepage:

No. Vision's internals mostly use XML, not JSON.

Thank you for this detailed explanation. Really appreciate you for taking the time and explaining this in detail…

Thank you for the explanation, I got it. @PGriffith