Zscaler Authenticate using API

Hi All,

We are using Utility Function REST API to call the Zscaler API from Resilient but we are getting 400 Authentication error.

Credentials are working correctly when we are calling API from Postman. Please let us know how to fix this issue. Attached is the code inside playbook task and error we are facing.


import json
import time
def obfuscateApiKey():
  seed = 'XXXXXXXXXXX'
  now = int(time.time() * 1000)
  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(r)), 1):
    key += seed[int(str(r)[j])+2]
  return now,key    
now , key = obfuscateApiKey()

content = json.dumps({'username':'admin@example.com','password':'password1234567','apiKey': key ,'timestamp':now})

inputs.rest_method = "POST"
inputs.rest_url = "https://zsapi.zscaler.net/api/v1/authenticatedSession"
inputs.rest_headers = '''

inputs.rest_body = content
inputs.rest_verify = True

Error status

The playbook was terminated by the system due to a function error.

Traceback (most recent call last):
File "/opt/app-root/lib/python3.6/site-packages/resilient_lib/components/requests_common.py", line 197, in execute
File "/opt/app-root/lib/python3.6/site-packages/requests/models.py", line 960, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: for url: https://zsapi.zscaler.net/api/v1/authenticatedSession

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/opt/app-root/lib/python3.6/site-packages/fn_utilities/components/utilities_call_rest_api.py", line 58, in _call_rest_api_function
headers_dict, cookies_dict, rest_body, rest_verify, rest_timeout)
File "/opt/app-root/lib/python3.6/site-packages/fn_utilities/components/utilities_call_rest_api.py", line 116, in make_rest_call
File "/opt/app-root/lib/python3.6/site-packages/resilient_lib/components/requests_common.py", line 205, in execute
raise IntegrationError(msg)
resilient_lib.components.integration_errors.IntegrationError: '400 Client Error: for url: https://zsapi.zscaler.net/api/v1/authenticatedSession