Retrieving the Authentication DSID
5 min
the data set identification (dsid) is required for api use the following curl command format uses the dsid to query the rest api server curl v cookie "dsid=\<value>" \<api request url> the dsid can be retrieved in two ways using the nzta api, see retrieving the dsid using the api docid mk5erknwxxx jyjr6ht4 using a browser, see retrieving the dsid using a browser docid mk5erknwxxx jyjr6ht4 retrieving the dsid using the api you can use the following code to get a dsid token to use across all api calls def login(url,username,password) tenant url = url return dict = {'status' 0} global user session, dsid login url = tenant url + '/login/admin' data = { 'username' username, 'password' password, 'realm' 'zta admin users', 'btnsubmit' 'submit', } user session = requests session() r = user session get(url=login url, verify=false) dssignin = user session cookies get('dssignin') data = {'username' username,'password' password,'realm' 'zta admin users','btncontinue' 'continue the session'} login cgi = url + '/dana na/auth/' + dssignin + '/login cgi' print login cgi r = user session post(url=login cgi, verify=false, data=data) print('login status code ', +r status code) print('login data ', user session cookies) d = str(r content) if 'continue the session' in d formdatastr = xsauth = none try p = r' name="formdatastr" value="( ?)">' x = re findall(p, d) formdatastr = x\[0] except indexerror print 'error unable to get formdatastr value' try p = r' name="xsauth" value="( ?)"' x = re findall(p, d) xsauth = x\[0] except indexerror print 'error unable to get xsauth value' data = {'formdatastr' formdatastr, 'xsauth' xsauth, 'btncontinue' 'continue the session'} login cgi = url + '/dana na/auth/' + dssignin + '/login cgi' r = user session post(url=login cgi, verify=false, data=data, allow redirects=true) dsid = user session cookies get('dsid') print ('dsid ', dsid) cookies\["dsid"]=dsid if dsid is none raise exception('loginerror unable to get dsid cookie') \# self cookie = dsid session = user session after the dsid is set in the cookies (refer to code dsid = user session cookies get('dsid') ) use that session for all other api calls you can use the following curl command format uses the dsid to query the rest api server curl v cookie "dsid=\<value>" \<api request url> the following code demonstrates how to get a list of secure access policies using the api it updates the cookie information for dsid from the above code def get secure access policies() input payload = {"type" "application"} request uri = host url + api version + "policies/secure access policies" output = requests get(request uri, params=input payload, cookies=cookies) status code = output status code response json = output json() print response json retrieving the dsid using a browser you can use a browser to access the dsid the procedure below describes the process for the chrome browser, but any browser that offers similar tools can also be used start the nzta user interface in the chrome browser the home page appears right click the main map, and select inspect from the context menu the screen divides horizontally and the element view appears to the right of the screen in the edge browser, you click the control, and then click other tools > developer tools in the firefox browser, you right click and select inspect element from the context menu in the element view, select the network tab select an element from the list of elements (on the left of the tab) for example, login , admin or subscriptions a tab bar appears (on the right of the tab) select the cookies tab a list of cookies for the page appears for the dsid entry, copy the dsid value and retain this value for future use for example element view in chrome browser you can use the following curl command format uses the dsid to query the rest api server curl v cookie "dsid=\<value>" \<api request url>
