Script to make an API call



If you are a Druva CloudRanger user, see [Getting started with CloudRanger APIs] (

Druva supports OAuth 2.0 based authentication for API requests. The following is the process to generate API credentials and create the Access Token to access the API requests. Sample scripts enable you to automate the process of creating the token and access Druva APIs.

Step 1: Generate API Credentials
API credentials can be created and managed from Druva Cloud Platform Console. Refer Create and Manage API Credentials to learn about API credentials management.

Sample API Credentials:


Step 2 - Script to form a Base64 encoded API Credential
After you generate the Client ID and Secret Key, encode it to Base64 format.

import os
import base64
bString = base64.b64encode("<Client ID>:<Secret Key>")

Replace the and with the values generated in Step 1 earlier.

import os
import base64
bString = base64.b64encode("McNkxxxx4Vicxxxx4Ldpxxxx/09Uxxxx:Xmcxxxx8j5xxxx6NxxxxRbRxxxxNNyPt")

Step 3: Use the Base64 encoded API Credential to generate an Access Token

Use appropriate URLs in the requests.
inSync Cloud - Use
inSync GovCloud - Use

import requests
tokenurl = ''
headers = {'Authorization': 'Basic ' + 'QXlxxxxxxKQytkOE5VS0adsfdU4SXR5M1lkRxxxxxxxTzAydGtENWpkNGw0NGZwbmxlMVNqxxxxxTktsSkU='}
payload = {
            'grant_type': 'client_credentials',
            'scope': 'read'
response =,headers=headers,data=payload)
respStatus_Code = response.status_code
if respStatus_Code == 200:
    responseJson = response.json()
    # Access token to be used
    bearer_token = responseJson.get('access_token')
    # Token expiry time in seconds
    expires_in = responseJson.get('expires_in')

Step 4: Use the Access Token to access Druva APIs.

import requests
url = ''
api_insync_events = '/insync/eventmanagement/v2/events'
# Token that was generated in step 3
headers = {'Authorization': 'Bearer ' +bearer_token}
response = requests.get(url+api_insync_events,headers=headers)
respStatus_Code = response.status_code
if(respStatus_Code == 200):
    responseJson = response.json()
    #get the values from the json here.
    #handle other error scenarios accordingly