Skip to main content

Instructor, no.

Incydr Professional, Enterprise, Horizon, and Gov F2, yes.

Incydr Basic, Advanced, and Gov F1, yes.

HOME
GETTING STARTED
RELEASE NOTES
FAQs
APIs
SYSTEM STATUS
Code42 Support

Tools for interacting with the Code42 API

Instructor, no.

Incydr Professional, Enterprise, Horizon, and Gov F2, yes.

Incydr Basic, Advanced, and Gov F1, yes.

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.

Code42 Developer Portal
See the Code42 Developer Portal for more API documentation and resources. The portal provides:

Use the Code42 Developer Portal for your API needs as much as possible. APIs in the portal are the preferred way to integrate with Code42 for Incydr users. If you use Code42 APIs that do not appear on the Code42 Developer Portal, contact our Technical Support Engineers for guidance on the best way to integrate with Code42. 

Considerations

The examples in this article use resource https://console.us.code42.com, but the resource you use depends on your Code42 cloud host address:

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 Technical Support Engineers 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, use 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 3 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:

Copied!
PS C:\Users\<admin> Invoke-WebRequest -Token <auth_token> -URi https://console.us.code42.com/api/v1/Computer -Method Get | Select-Object Content | ConvertTo-Json

In the example, replace <auth_token> with an authentication token

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 Mac

Example command

The following command lists the devices in your Code42 environment:

Copied!
curl -X GET -k 'https://console.us.code42.com/api/v1/Computer' -H 'Authorization: Bearer <auth_token>' | python3 -mjson.tool

In the example, replace <auth_token> with an authentication token

For additional examples, see our Code42 API syntax and 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:

Copied!
curl -X GET -k 'https://console.us.code42.com/api/v1/Computer' -H 'Authorization: Bearer <auth_token>' | python3 -mjson.tool

In the example, replace <auth_token> with an authentication token

For additional examples, see our Code42 API syntax and usage article.

Copy curl commands from the Code42 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 Code42 console action.

  1. Use Chrome or Firefox to sign in to the Code42 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 Code42 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:

Copied!
Invoke-WebRequest -Token <auth_token> -URi https://console.us.code42.com/api/v1/Computer -Method Get

In the example, replace <auth_token> with an authentication token

Program languages

Python

To interact with the Code42 API in Python, use 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://console.us.code42.com/api/v1/Computer', auth=BearerAuth('<auth_token>'))

print r.status_code
print r.text

In the example, replace <auth_token> with an authentication token

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://console.us.code42.com/api/v1/Computer', auth=BearerAuth('<auth_token>'))
>>> 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":"Code42"},{"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":"Code42"},{"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":"Code42"}]}}'

Ruby

To interact with the Code42 API in Ruby, use 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.authorization :Bearer, '<auth_token>'

response = conn.get 'https://console.us.code42.com/api/v1/Computer'
puts response.status
puts response.body

In the example, replace <auth_token> with an authentication token

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.authorization :Bearer, '<auth_token>'
=> "Basic YWRtaW46YWRtaW4="
irb(main):004:0> conn.get 'https://console.us.code42.com/api/v1/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\":\"Code42\"},{\"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\":\"Code42\"},{\"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\":\"Code42\"}]}}" @url=#<URI::HTTP:0x0000000265d568 URL:https://console.us.code42.com/api/v1/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://console.us.code42.com/api/v1/Computer", "content-type"=>"application/json;charset=UTF-8", "connection"=>"close", "server"=>"Jetty(7.6.15.v20140411)"} @status=200>>

Related topics

  • Was this article helpful?