Skip to main content
Code42 Support

Tools For Interacting With The Code42 API

Available in:

  • CrashPlan PRO
    • Standard
    • Premium
    • Enterprise
Applies to:

Overview

The Code42 API is accessible through many tools, such as web browsers, scripting tools, and programming languages. This article provides links to third-party tools that you can use to interact with the Code42 API.

Considerations

Code42 server SSL certificate

The examples in this article assume that your Code42 server has a signed SSL certificate that is trusted by your client computer. If your Code42 server does not have a signed certificate, API requests that use HTTPS may fail. To avoid these errors, take either of the following actions:

Third-party software

This article provides resources and basic usage examples for interacting with the Code42 API using third-party software. Refer to documentation provided by the software's manufacturer for more detailed information.

Non-Code42 products
​Information about products from other manufacturers is intended as a resource to help you get the most out of Code42 products. However, our Customer Champions cannot provide direct assistance for these products. For assistance with products not developed by Code42, contact the product's manufacturer.

Web browsers

The Code42 API is HTTP-based, so you can use a web browser to interact with it:

  • Unmodified web browsers can examine Code42 API resources with the GET method because navigating to an API URL generates an HTTP GET request. Install a JSON formatter to make the return values easier to read.
  • REST client extensions expand browser functionality by allowing you to select a method (GET, PUT, POST, or DELETE) to interact with the Code42 API.

JSON formatter extensions

Install a JSON formatting extension to make return values easier to read.

Browser JSON Formatter Extensions
Chrome

JSON Formatter

JSON-handle

Firefox

JSONView

JSON-handle

Safari JsonView

REST client extensions

Install a REST client extension to use the PUT, POST, and DELETE methods from a web browser.

Browser REST Client Extensions
Chrome

Postman

Advanced REST Client

Firefox

REST Easy

RESTClient

Script tools

For scripting the Code42 API, we recommend curl and Windows PowerShell.
Both work best when they can call Python's json.tool

Python's JSON.tool

json.tool is a Python JSON encoder and decoder that can be used to make Code42 API output more readable. The json.tool requires that Python be installed on the system.

Return JSON instead of PowerShell objects

If you want the API command to return JSON instead of a PowerShell object, add the ConvertTo-Json cmdlet:

PS C:\Users\admin> Invoke-WebRequest -Credential username -URi https://master-server.example.com:4285/api/Computer -Method Get | Select-Object Content | ConvertTo-Json

Curl

Curl is a command-line tool that can be used to submit and receive data over many protocols, including HTTP and HTTPS.

Linux and OS X

Example command

The following command lists the devices in your Code42 environment:

curl -X GET -k -u "username:password" 'https://master-server.example.com:4285/api/Computer' | python -m json.tool

For additional examples, see our Code42 API Syntax & Usage article.

Windows

Install Cygwin, which provides a Unix-like command-line interface for Windows, with the curl package. When you run setup.exe, on the Select Packages window make sure to select curl from within the net category, and select Python.

You can run curl examples with the same switches on Windows. Not only can you run curl from the Cygwin shell, you can also run curl from the Windows cmd shell if you add the Cygwin binary path to the Windows PATH system environment variable (for example, ;C:\cygwin64\bin).

Example command

The following command lists the devices in your Code42 environment:

curl -X GET -k -u "username:password" 'https://master-server.example.com:4285/api/Computer' | python -m json.tool

For additional examples, see our Code42 API Syntax & Usage article.

Copy curl commands from the administration console

Chrome and Firefox include the option to copy a network request as a curl command. You can use this functionality to create a curl command that duplicates the functionality of an administration console action.

  1. Use Chrome or Firefox to sign in to the administration console.
  2. Navigate to the page that contains the command you want to copy.
  3. Open the Chrome or Firefox developer tools, then click Network.
  4. Initiate the action in the administration console that you want to copy.
    A network request that corresponds to the action appears in the developer tools.
  5. In the developer tools, right-click the network request, then select Copy as cURL.
  6. Paste the copied curl command in a text editor and modify the command as needed.

Windows PowerShell

Scripting interaction with the Code42 API on Windows relies on the PowerShell Invoke-RestMethod utility cmdlet.

  • Invoke-RestMethod is available in PowerShell 3.0 and later.
  • The return value is formatted as a PowerShell object.

Example command

The following command lists the devices in your Code42 environment:

Invoke-WebRequest -Credential username -URi https://master-server.example.com:4285/api/Computer -Method Get

Program languages

Python

To interact with the Code42 API in Python, we recommend using the Requests library. The following examples use Requests to run a simple GET method on the Computer resource.

Requests must be installed before the examples are executed.

Script example

import requests

r = requests.get('https://master-server.example.com:4285/api/Computer', auth=('username', 'password'))

print r.status_code
print r.text

Interactive example

user@UbuntuLTS:~$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> r=requests.get('https://master-server.example.com:4285/api/Computer', auth=('username','password'))
>>> print r
<response>
>>> r.text
u'{"metadata":{"timestamp":"2015-03-27T12:19:27.632-05:00","params":{}},"data":{"computers":[{"computerId":13,"name":"WIN-FQNN6BGK47K","guid":"681099810721783680","type":"COMPUTER","status":"Active, Deauthorized","active":true,"blocked":false,"alertState":0,"alertStates":["OK"],"userId":2,"orgId":2,"parentComputerId":null,"lastConnected":"2015-03-18T16:42:55.482-05:00","osName":"win","osVersion":"6.2","osArch":"amd64","address":"192.168.95.128:4242","remoteAddress":"172.16.239.1","javaVersion":"1.7.0_45","modelInfo":null,"timeZone":"America/Chicago","version":1388728800370,"productVersion":"3.7.0","buildVersion":null,"creationDate":"2015-03-18T16:39:04.241-05:00","modificationDate":"2015-03-24T09:39:21.135-05:00","loginDate":"2015-03-18T16:39:07.570-05:00","service":"CrashPlan"},{"computerId":12,"name":"WIN-FQNN6BGK47K","guid":"680201360538886016","type":"COMPUTER","status":"Active","active":true,"blocked":false,"alertState":0,"alertStates":["OK"],"userId":2,"orgId":2,"parentComputerId":null,"lastConnected":"2015-03-12T17:17:23.909-05:00","osName":"win","osVersion":"6.2.9200.0","osArch":null,"address":"192.168.95.128:4252","remoteAddress":"172.16.239.1","javaVersion":null,"modelInfo":null,"timeZone":null,"version":1413349200416,"productVersion":"3.7.0","buildVersion":31,"creationDate":"2015-03-12T11:53:40.861-05:00","modificationDate":"2015-03-12T17:17:23.909-05:00","loginDate":"2015-03-12T16:23:12.272-05:00","service":"CrashPlan"},{"computerId":10,"name":"WIN-FQNN6BGK47K","guid":"680190841811656576","type":"COMPUTER","status":"Active","active":true,"blocked":false,"alertState":0,"alertStates":["OK"],"userId":2,"orgId":2,"parentComputerId":null,"lastConnected":"2015-03-13T13:15:49.352-05:00","osName":"win","osVersion":"6.2.9200.0","osArch":null,"address":"192.168.95.128:4252","remoteAddress":"172.16.239.1","javaVersion":null,"modelInfo":null,"timeZone":null,"version":1413349200416,"productVersion":"3.7.0","buildVersion":null,"creationDate":"2015-03-12T11:51:13.871-05:00","modificationDate":"2015-03-13T13:15:49.352-05:00","loginDate":"2015-03-12T11:51:13.867-05:00","service":"CrashPlan"}]}}'

Ruby

To interact with the Code42 API in Ruby, we recommend using the Faraday gem. The following examples use Faraday to run a simple GET method on the Computer resource. Faraday must be installed before the examples are executed.

Script example

require 'faraday'

conn = Faraday.new
conn.basic_auth('username', 'password')

response = conn.get 'https://master-server.example.com:4285/api/Computer'
puts response.status
puts response.body

Interactive example

user@UbuntuLTS:~$ irb
irb(main):001:0> require 'faraday'
=> true
irb(main):002:0> conn = Faraday.new
=> #<:connection:0x00000001c359f0>"Faraday v0.9.1"}, @params={}, @options=#<:requestoptions>, @ssl=#<:ssloptions>, @default_parallel_manager=nil, @builder=#<:rackbuilder:0x00000001c354f0>, @url_prefix=#<:http:0x00000001fcffe8>, @proxy=nil>
irb(main):003:0> conn.basic_auth('username', 'password')
=> "Basic YWRtaW46YWRtaW4="
irb(main):004:0> conn.get 'https://master-server.example.com:4285/api/Computer'
=> #<Faraday::Response:0x00000002666528 @on_complete_callbacks=[], @env=#<Faraday::Env @method=:get @body="{\"metadata\":{\"timestamp\":\"2015-03-27T12:53:50.741-05:00\",\"params\":{}},\"data\":{\"computers\":[{\"computerId\":13,\"name\":\"WIN-FQNN6BGK47K\",\"guid\":\"681099810721783680\",\"type\":\"COMPUTER\",\"status\":\"Active, Deauthorized\",\"active\":true,\"blocked\":false,\"alertState\":0,\"alertStates\":[\"OK\"],\"userId\":2,\"orgId\":2,\"parentComputerId\":null,\"lastConnected\":\"2015-03-18T16:42:55.482-05:00\",\"osName\":\"win\",\"osVersion\":\"6.2\",\"osArch\":\"amd64\",\"address\":\"192.168.95.128:4242\",\"remoteAddress\":\"172.16.239.1\",\"javaVersion\":\"1.7.0_45\",\"modelInfo\":null,\"timeZone\":\"America/Chicago\",\"version\":1388728800370,\"productVersion\":\"3.7.0\",\"buildVersion\":null,\"creationDate\":\"2015-03-18T16:39:04.241-05:00\",\"modificationDate\":\"2015-03-24T09:39:21.135-05:00\",\"loginDate\":\"2015-03-18T16:39:07.570-05:00\",\"service\":\"CrashPlan\"},{\"computerId\":12,\"name\":\"WIN-FQNN6BGK47K\",\"guid\":\"680201360538886016\",\"type\":\"COMPUTER\",\"status\":\"Active\",\"active\":true,\"blocked\":false,\"alertState\":0,\"alertStates\":[\"OK\"],\"userId\":2,\"orgId\":2,\"parentComputerId\":null,\"lastConnected\":\"2015-03-12T17:17:23.909-05:00\",\"osName\":\"win\",\"osVersion\":\"6.2.9200.0\",\"osArch\":null,\"address\":\"192.168.95.128:4252\",\"remoteAddress\":\"172.16.239.1\",\"javaVersion\":null,\"modelInfo\":null,\"timeZone\":null,\"version\":1413349200416,\"productVersion\":\"3.7.0\",\"buildVersion\":31,\"creationDate\":\"2015-03-12T11:53:40.861-05:00\",\"modificationDate\":\"2015-03-12T17:17:23.909-05:00\",\"loginDate\":\"2015-03-12T16:23:12.272-05:00\",\"service\":\"CrashPlan\"},{\"computerId\":10,\"name\":\"WIN-FQNN6BGK47K\",\"guid\":\"680190841811656576\",\"type\":\"COMPUTER\",\"status\":\"Active\",\"active\":true,\"blocked\":false,\"alertState\":0,\"alertStates\":[\"OK\"],\"userId\":2,\"orgId\":2,\"parentComputerId\":null,\"lastConnected\":\"2015-03-13T13:15:49.352-05:00\",\"osName\":\"win\",\"osVersion\":\"6.2.9200.0\",\"osArch\":null,\"address\":\"192.168.95.128:4252\",\"remoteAddress\":\"172.16.239.1\",\"javaVersion\":null,\"modelInfo\":null,\"timeZone\":null,\"version\":1413349200416,\"productVersion\":\"3.7.0\",\"buildVersion\":null,\"creationDate\":\"2015-03-12T11:51:13.871-05:00\",\"modificationDate\":\"2015-03-13T13:15:49.352-05:00\",\"loginDate\":\"2015-03-12T11:51:13.867-05:00\",\"service\":\"CrashPlan\"}]}}" @url=#<URI::HTTP:0x0000000265d568 URL:https://master-server.example.com:4285/api/Computer> @request=#<Faraday::RequestOptions (empty)> @request_headers={"User-Agent"=>"Faraday v0.9.1", "Authorization"=>"Basic YWRtaW46YWRtaW4="} @ssl=#<Faraday::SSLOptions (empty)> @response_headers={"cache-control"=>"no-store", "pragma"=>"no-cache", "content-location"=>"https://master-server.example.com:4285/api/v1/Computer", "content-type"=>"application/json;charset=UTF-8", "connection"=>"close", "server"=>"Jetty(7.6.15.v20140411)"} @status=200>>
  • Was this article helpful?