Skip Navigation

Generate an access token

The access token can be generated using Python. You can use the Python example below, adding the required token claims that you need.
The following requirements and script are just an example. This may change based on end-user requirements (example: using a different version of Python).
Software requirements
  • Python 3.7 or higher (available from https://www.python.org/downloads/). Make sure to set the following options during installation:
    • Check the
      Add Python <version> to PATH
      checkbox at the beginning of the Python installation.
    • Click
      Disable path length limit
      to remove the 260 character MAX_PATH limitation at the end of the installation.
  • Python Requests Library 2.22.0 or higher:
    • Open a command prompt on the machine where Python is installed, then run the following command to install the latest Requests library:
      python -m pip install requests
You will need to use the access token to execute the API requests.
Example Script
The following example code can be used to get an access token using Python.
import requests # requests version 2.22.0 as of the time of authoring # Set the base url. Example: https://login.onprem-cylance.com. This url # will be specific to your installation of CylanceON-PREM. onprem_base_url = "<your_base_url>" # Set the Application ID appID = "<your_app_id>" # Set the Application Secret appSecret = "<your_app_secret>" # Make a POST request to get the application token. token_headers = { "Content-Type": "application/json", "Accept": "application/json", } token_request_body = { "clientId": appID, "clientSecret": appSecret, "scope": "*" } token_url = f"{onprem_base_url}/cyapi/v1/application/token" token_result = requests.post(token_url, json=token_request_body, headers=token_headers,verify=False) token_url_json_results = token_result.json() print("Got result from token request:") print(token_url_json_results)