RestAPI example files

RestAPI example files

Background:
CPM contain rich RESTful API interface that enable you to do everything you do manually in the UI in an automated way, but it can be difficult to start using the RESTful API.
We created this examples to assist customers in understanding our API’s and start using them.

In addition to this KB, you can find the full RESTful API guide here https://n2ws.com/support/documentation 
and another KB with additional info/examples here:  Restful API examples for 3.0.x
This code is just an example to assist in understanding our API’s and is given with no warranty or support, it is your responsibility to test it and 100% understand it before using code in production

Examples details:
The target audience for the examples are developers and each example file has a comment with the version of CPM used to create it.

The attached zip contain the following files:
  1. Utils.pyutility class for functions that are used in more then one example file, for example we have here the requests.post that handle the API calls for the various examples.
  2. WorkingWithAPIKEY.py - General example, show how to use get token and refresh token
  3. WorkingWithPolicies.py - General example, shows various API's for policies (get policy, list policy, list targets, create policy, update policy, delete policy)
  4. WorkingWithRecovery.py - General example,  shows various API's for recovery (getting info and doing recovery)
  5. WorkingWithReports.py - General example, shows various API's for Reports  (getting audit, backup and summery report)
  6. CustomExcelReport(AWS).py - Scenario example, here we are collecting info from environment (policy list, account list, backups, recoveries, etc...) and printing it to one xlsx file 
Tip: Understanding how some operation is done via UI will help to automate it using the RestApi's, for example when you recover EC2 instance you need to select backup record in the backup monitor and then select relevant snapshot to recover, so when doing the same via Apis' you will first need to gather info (backup record id, snapshot id, etc...) before calling the recover Api command.

How to get API Key:
Each user has it's own API key, to enable API access and key, click on User -> Setting


Then click on API Access -> enable the checkbox -> Generate and Save API Authentication Key