urlLookup is broken in API

api

(Sterling Brockwell) #1

I had to API working for us to do a url lookup on custom categories to see if there were any duplicate categories or mis-configured urls. But not it returns nothing when doing the urlLookup.

I can still get the API to return the urlCategories but the response is always empty for urlLookup. Please note that it was working for a while and then I ran it again just a while ago and now it fails to return anything. If someone who knows the backend of the API could help me, that would be great. The following code is python and in order to run it, put “python .\ThisScript.py YourName@YourDomain.com YourPassword YoUrAPikEy”

import sys, json, time, urllib2, time

from cookielib import CookieJar

##################################################
# this function obfuscates the key to be used to interface with Zscaler
def obfuscateApiKey (api_key,timestamp):
seed = api_key
now = int(timestamp)
n = str(now)[-6:]
r = str(int(n) >> 1).zfill(6)
key = “”
for i in range(0, len(str(n)), 1):
key += seed[int(str(n)[i])]
for j in range(0, len(str®), 1):
key += seed[int(str®[j])+2]
return key
##################################################
# this function performs the lookup on the list of URLs provided
def lookupURL(opener,urlList):
req=urllib2.Request(‘https://admin.zscalerone.net/api/v1/urlLookup’,json.dumps(urlList),{‘content-type’:‘application/json’,‘cache-control’:'no-cache’})
response=opener.open(req)
print '\nResponse: '+ str(response)
return response.read().decode(‘utf-8’)
##################################################
##################################################
# main function
if name==‘main’:
timestamp=time.time()*1000
if len(sys.argv) < 4:
print ‘\nYou must include your Zscaler credentials and API key as arguments when running the script!\nExample: “python .\ThisScript.py YourName@YourSchool.edu YourPassword YoUrAPikEy”\n\n’
quit()
else:
auth={‘username’:sys.argv[1],‘password’:sys.argv[2],‘apiKey’:obfuscateApiKey(sys.argv[3],timestamp),‘timestamp’:str(int(timestamp))}
jar=CookieJar()
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))

##################################################
try:
    req=urllib2.Request('https://admin.zscalerone.net/api/v1/authenticatedSession',json.dumps(auth),{'content-type':'application/json','cache-control':'no-cache'})
    response=opener.open(req)
    
    req=urllib2.Request('https://admin.zscalerone.net/api/v1/urlCategories',headers={'content-type':'application/json','cache-control':'no-cache'})
    response=opener.open(req)
    
    categories=json.loads(response.read().decode('utf-8'))
        # for each category recieved 
    for cat in categories:
            # if the category has urls 
        if len(cat['urls'])>0:
            print '\n-----------------------\nList to Lookup: '+str(cat['urls'])

            zsCategories=json.loads(lookupURL(opener,cat['urls']))
            print '\nReceived Categories: '+str(zsCategories)
            #ZS Rate limits calls to urllookup
            time.sleep(1.1)
##################################################              
except urllib2.HTTPError, e:
    print 'Error (code %s) %s :' % (str(e.code),str(sys.exc_info()[0]))
    print e.readlines()

(Lidor Pergament) #2

Hi @SterlingB,

If I understood your question correctly, please let me clarify:

urlLookup only returns matches from our global categorization database. it will not return a result for a custom URL that only belongs to a Custom URL Category. You will have to progamatically search in Python for the URLs you added to your custom categories.

Let us know if you require further assistance.

Lidor


(Gordon Wright) #3

I seem to have a similar problem looking up Global Categories. It just returns a blank.


(Gordon Wright) #4

I’ve had someone else confirm that the urlLookup api returns no data in Zscaler Beta. I’ll raise a support ticket for it now.


(Yogi Chandiramani) #5

Hi

for me url lookup does work :

ys-MacBook-Pro:scripts ychandiramani$ python urllookup.py -u www.yogi.com

Logged in successfully in API

“url”:“www.yogi.com”,“urlClassifications”:“ALT_NEW_AGE”,“urlClassificationsWithSecurityAlert”:

Logged off successfully from API


(Gordon Wright) #6

Zscaler have confirmed this is an issue in the Zscaler Beta Cloud only. They have raised a BUG report - The BUG ID is BUG-50301.