Skip to main content
Code42 Support

Sample Uses Of The Code42 API

Applies to:
  • CrashPlan PROe

Overview

The Code42 API is a REST-based API you can use to create custom reports, perform automated actions, or integrate with existing systems within your organization. This article shows some of the many ways you can use the Code42 API to interact with your Code42 environment.

Before you begin

Several examples below use Python (specifically, the python -mjson.tool formatting tool) to properly format their output. This requires Python 2.5 or higher. Python is installed by default on Mac OS X and many Linux distributions.

If your system does not have Python, you can install it from the official download page.

GitHub

GitHub is a popular open source code repository and social platform for developers. You can find additional API examples, code libraries, scripts, and developer documentation on Code42's GitHub page. Everyone is welcome to contribute.  

Examples

Computers

Backup status of devices sorted by user

The Code42 API makes it easy to see the last time a user's device was completely backed up. The following example uses the Computer resource and limits the output with active=true, includes backup usage, and sorts the output by the date of the most recent backup. Once the userID is known, this example could be altered to report only the details of a single user.

curl -sku admin "https://myserver.example.com:4285/api/Computer?active=true&incBackupUsage=true&srtKey=lastBackup"

Sample output:

{

    "metadata": {
        "timestamp": "2014-08-07T15:31:21.466-05:00",
        "params": {
            "incBackupUsage": "true",
            "srtKey": "lastBackup",
            "active": "true"
        }
    },
    "data": {
        "computers": [
            {
                "computerId": 10,
                "name": "Alpha",
                "guid": "619174385806213377",
                "type": "COMPUTER",
                "status": "Active",
                "active": true,
                "blocked": false,
                "alertState": 0,
                "alertStates": [
                    "OK"
                ],
                "userId": 2,
                "orgId": 2,
                "parentComputerId": null,
                "lastConnected": "2014-08-07T15:14:04.234-05:00",
                "osName": "Linux",
                "osVersion": "3.2.0-4-686-pae",
                "osArch": "i386",
                "address": "127.0.0.1:4242",
                "remoteAddress": "127.0.0.1",
                "javaVersion": "1.6.0_27",
                "modelInfo": null,
                "timeZone": "US/Central",
                "version": 1375333203614,
                "productVersion": "3.6.1.4",
                "creationDate": "2014-08-01T16:37:51.131-05:00",
                "modificationDate": "2014-08-07T15:14:09.645-05:00",
                "loginDate": "2014-08-07T15:14:09.641-05:00",
                "backupUsage": [
                    {
                        "targetComputerId": 2,
                        "targetComputerParentId": null,
                        "targetComputerGuid": "647903643760066817",
                        "targetComputerName": "CrashPlan PROe Server",
                        "targetComputerOsName": null,
                        "targetComputerType": "SERVER",
                        "selectedFiles": 8,
                        "selectedBytes": 21944,
                        "todoFiles": 0,
                        "todoBytes": 0,
                        "archiveBytes": 111170,
                        "billableBytes": 111170,
                        "sendRateAverage": 70139,
                        "completionRateAverage": 0,
                        "lastBackup": "2014-08-07T15:14:12.802-05:00",
                        "lastCompletedBackup": "2014-08-07T15:14:12.802-05:00",
                        "lastConnected": "2014-08-07T15:16:45.469-05:00",
                        "lastMaintenanceDate": "2014-08-01T16:38:13.955-05:00",
                        "lastCompactDate": null,
                        "modificationDate": "2014-08-07T15:16:45.469-05:00",
                        "creationDate": "2014-08-01T16:38:13.958-05:00",
                        "using": true,
                        "alertState": 0,
                        "alertStates": [
                            "OK"
                        ],
                        "percentComplete": 100,
                        "storePointId": 1,
                        "storePointName": "Default",
                        "serverId": 3,
                        "serverName": "CrashPlan PROe Server",
                        "serverHostName": "http://alpha:4280",
                        "isProvider": false
                    }
                ]
            },
            {
                "computerId": 11,
                "name": "Beta",
                "guid": "631663249095393537",
                "type": "COMPUTER",
                "status": "Active",
                "active": true,
                "blocked": false,
                "alertState": 0,
                "alertStates": [
                    "OK"
                ],
                "userId": 3,
                "orgId": 2,
                "parentComputerId": null,
                "lastConnected": "2014-08-07T15:26:14.212-05:00",
                "osName": "Linux",
                "osVersion": "3.2.0-4-686-pae",
                "osArch": "i386",
                "address": "172.16.195.139:4242",
                "remoteAddress": "172.16.195.139",
                "javaVersion": "1.6.0_27",
                "modelInfo": null,
                "timeZone": "US/Central",
                "version": 1375333203614,
                "productVersion": "3.6.1.4",
                "creationDate": "2014-08-07T15:26:12.274-05:00",
                "modificationDate": "2014-08-07T15:26:16.615-05:00",
                "loginDate": "2014-08-07T15:26:14.309-05:00",
                "backupUsage": [
                    {
                        "targetComputerId": 2,
                        "targetComputerParentId": null,
                        "targetComputerGuid": "647903643760066817",
                        "targetComputerName": "CrashPlan PROe Server",
                        "targetComputerOsName": null,
                        "targetComputerType": "SERVER",
                        "selectedFiles": 588,
                        "selectedBytes": 798675763,
                        "todoFiles": 588,
                        "todoBytes": 798675763,
                        "archiveBytes": 357,
                        "billableBytes": 357,
                        "sendRateAverage": 92047,
                        "completionRateAverage": 0,
                        "lastBackup": "2014-08-07T15:27:08.191-05:00",
                        "lastCompletedBackup": null,
                        "lastConnected": "2014-08-07T15:29:45.648-05:00",
                        "lastMaintenanceDate": "2014-08-07T15:27:05.388-05:00",
                        "lastCompactDate": null,
                        "modificationDate": "2014-08-07T15:29:45.648-05:00",
                        "creationDate": "2014-08-07T15:27:05.389-05:00",
                        "using": true,
                        "alertState": 0,
                        "alertStates": [
                            "OK"
                        ],
                        "percentComplete": 0,
                        "storePointId": 1,
                        "storePointName": "Default",
                        "serverId": 3,
                        "serverName": "CrashPlan PROe Server",
                        "serverHostName": "http://alpha:4280",
                        "isProvider": false
                    }
                ]
            }
        ]
    }

}

Count devices reporting CrashPlan app version x

One common use of the Code42 API is to identify how many devices are running a specific version number. This can be useful after the server has been upgraded to confirm that the devices have automatically upgraded. The example below uses the Computer resource, limits the output to only active devices with active=true, and exports the data. Grep then filters the output to count the number of instances of the version string ,3.6.3,.

curl -sku admin "https://master-server.example.com:4285/api/Computer?export=csv&active=true" | grep -c ,3.6.1.4,

The command outputs the total number of active devices (up to 999) running version 3.6.3.

Note that the Computer resource includes both mobile devices and computers.

CrashPlan app versions other than x

If you have a large CrashPlan PROe environment, (more than 1000 devices), working with long lists of information via standard output (stdout) can be cumbersome. You can export the list to a CSV file and then manipulate the data with utilities such as awk or Microsoft Excel. Awk is a text-processing programming language and is a useful tool for manipulating text files.

The example below uses curl, grep, and awk to display a list of active devices reporting a version other than the current version (in this example, the current version is 3.6.3). This can be a useful script following a large upgrade to see which client versions exist in the environment.

The example uses the Computer resource. Output is limited to active devices (active=true) and then exported. The exported output contains all computer resource properties for active devices reporting a current version other than 3.6.3. We use grep to remove the header row and then redirect the output to a text file named “devices.txt”. We then use awk to process the text file and display only the lines that do not contain the version number 3.6.3.

curl -sku admin "https://master-server.example.com:4285/api/Computer?export=csv&active=true" | python -mjson.tool | grep ,, > devices.txt
awk -F "," '$18 != "3.6.3" {print $18}' devices.txt

Sample output:

3.2.1
3.3
3.4.1

Users

Security audit for admin access

As a Code42 environment grows over time, a large number of administrators may be involved with daily management. The following example uses the Users resource to list all of the active users with the assigned roleId=10, which corresponds to Org Admin. The output is then filtered with the grep utility to show only rows containing the usernames.

curl -sku admin "https://master-server.example.com:4285/api/User?active=true&pgSize=999&roleId=10&incRoles=true" | python -mjson.tool | grep -w username

Sample output:

"username": "michelle.lee@example.com",
      "username": "chris.crashplan@example.com",
      "username": "joe.johnson@example.com",

Move a user

You can move a user to a different organization by passing parameters to the Code42 API. Here the user account with userID=307 is moved to the organization with parentOrgId=71.

curl -v -H "Content-Type: application/json" -u admin -X POST -d '{"userId":307,"parentOrgId":71}' https://master-server.example.com:4285/api/UserMoveProcess

External resources

Code42 houses additional Code42 API resources on GitHub.

You can download Python here:

Links to download the Windows version of the command line tools used in these examples are below.