We need to be able to query the REST end point for the portal machines to determine the primary and standby machines but not sure what the syntax needs to be for accessing it outside the portal administrator.
The REST end point is https://admin.portal...../arcgis/portaladmin/machines?f=pjson which works when I am in the portal admin but how do we add this to an external application with credentials / token?
ah gotcha,
So the initial query is to get the machine names:
https://machine.domain.com/webadaptor/portaladmin/machines
then the status for each machine:
https://machine.domain.com/webadaptor/portaladmin/machines/status/MACHINE.DOMAIN.COM?f=json
the token is generated with:
import requests portalUrl = "https://domain/portal" username = 'username' password = "password" def generateToken(username, password, portalUrl): # Retrieves a token to be used with API requests. headers = {'content-type': 'application/x-www-form-urlencoded'} parameters = {'username': username, 'password': password, 'client': 'referer', 'referer': portalUrl, 'expiration': 60, 'f': 'json'} url = portalUrl + '/sharing/rest/generateToken?' response = requests.post(url, data=parameters, headers=headers) try: jsonResponse = response.json() if 'token' in jsonResponse: return jsonResponse['token'] elif 'error' in jsonResponse: print (jsonResponse['error']['message']) for detail in jsonResponse['error']['details']: print (detail) except ValueError: print('An unspecified error occurred.') print(ValueError) token = generateToken(username, password, portalUrl) print(token)
would you want to do this with requests or the rest api for python?
Thanks @DavidPike we are looking to do as a request from an external script that needs to shut down the portal in a specific order depending on the machine status in HA
@DavidPike wrote:would you want to do this with requests or the rest api for python?
gotcha, so you'd want to do a health check via the REST API Health Check—ArcGIS REST API | ArcGIS for Developers but need to know how to generate and attach the token for access?
Yes exactly. We are stuck on how to create and pass the relevant credentials through to the rest end point
Hello @DavidPike I have been told that there is a proxy in place and that could be causing the issue of not being able to get the results I need. Do you know how to use the proxy https://cls-bx-proxy with what you have suggested above?
can you elaborate on the issue?
I am getting a token returned using the script but I then get a 'Forbidden 403' message. So it has been suggested to use the proxy server but not sure how to configure that into the script.
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.