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




    • Related Articles

    • Restful API examples

      The purpose of this article is to help you get started with N2WS Restful API and provide you some examples on how to use it. However, it is not meant to replace the official documentation - for full and accurate information on all the APIs and ...
    • CPM RESTful API guide for CPM v2.6.0

      Attached to this article is the user guide for CPM RESTful API v1.3 (for CPM v2.6.0 and up). For CPM CLI information see here: https://support.n2ws.com/portal/kb/articles/cli-guide-and-software-download-for-cpm-v2-6-0 You can find the latest version ...
    • Basic API example for CPM login and retrieving the list of CPM users using powershell

      The below script provides a basic example for the usage of CPM API with Powershell. Copy the below text into a .ps1 file, replace the text in blue with your relevant text and run the script. ...
    • N2WS-18738 - Password saved as plain text for Recovery Scenario target added via RestAPI

      Issue: When creating Recovery Scenario(CPM v3.0 and up) and adding a backup target via Rest API, it will save the following details as plain text Proxy password for S3 instance recovery if used IAM AWS Secret Key when providing alternate Credential ...
    • CLI guide and software download for CPM v4.0.0

      CLI v2.0 for CPM v4.0.0 and the user guide are available for download as attachments to this solution Previous version: CLI guide and software download for CPM v3.2.1x Next version: CLI guide and software download for CPM v4.1.0x