Carbon Black Cloud: How To Install Python Based CB REST API On Windows
search cancel

Carbon Black Cloud: How To Install Python Based CB REST API On Windows

book

Article ID: 290035

calendar_today

Updated On:

Products

Carbon Black Cloud Endpoint Standard (formerly Cb Defense) Carbon Black Cloud Enterprise EDR (formerly Cb Threathunter)

Issue/Introduction

How To Install Python Based CB REST API On Windows 

Environment

  • Carbon Black Cloud: All Supported Versions
  • Microsoft Windows: All Supported Versions
  • Python: All Supported Versions

Resolution

  1. Install Python How to Install Python On Windows
  2. Install Pip How to Install PIP on Windows
  3. Once the Python and pip are installed open a command prompt and run the following command line:
pip install cbapi
  1. Cbapi will be installed in the location where you have installed python. So navigate to the python folder, For example, in windows machine the default location is: C:\Python27\Scripts
  2. Once changed the directory to C:\Python27\Scripts, run the following command line: 
python cbapi-defense configure
  1. Once the cbapi-defense is configured, it will ask for the URL to the CB Defense API server. Please find your respective backend URL using:API URL
  2. Once entered the API URL it will prompt for Connector ID and API Key. Please find the steps below to create an API key:
  • Log into the CB Cloud console
  • Go to settings
  • Go to API Access
  • Create an API Access key
  1. After entering the API credentials, a credential.defense file will be created in the user location, for example: C:\Users\Administrator\.carbonblack\credential.defense
  2. Open the credentials.defense file with notepad and save as .INI file in the same location and rename the credentials.defense to credentials.psc. There should be two files as shown below:
credentials.INI
credentials.psc
  1. Once the changes made, you should be able to run the script to retrieve the information using cbapi.

Additional Information

Note: Make sure that python and pip should be installed on the machine before installing cbapi.

Example output:
  • Few cbapi-python sample scripts are available in the Git-hub. Please follow this link: https://github.com/carbonblack/cbapi-python/tree/master/examples/defense
  • Save the raw script locally on the machine and run the script. For example: C:\api>python list_devices.py
  • Output as follows:
    C:\api>python list_devices3.py
    ID        Hostname                                IP Address        Last Checkin
     Time
     20755512 LINUXlab                                10.70.1.xxx       1970-01-01 0
    0:00:00
     20748067 GovaTesting                             10.70.1.xxx       1970-01-01 0
    0:00:00
     21203863 Gova2019                                10.70.1.xxx       1970-01-01 0
    0:00:00
     22758394 WIND10-Rameez                           10.70.1.45        1970-01-01 0