Carbon Black & VMware Announce Expanded Partnership to Secure the Software-Defined Data Center (SDDC) Learn more

Introducing .NET Client for Carbon Black API

CarbonBlack-Logo-Primary-RGBBlack
Hex_Honeycomb
November 24, 2014 / Jeremiah Clark

For a developer, one of the coolest things about Carbon Black is the REST API. The API wasn’t an afterthought; it serves as the foundational input/output layer for the entire Carbon Black server.

The UI is built completely as a consumer of the API. This is great for developers who like to extend the out-of-the-box features provided by the Carbon Black server.

In addition to the standard URL-based usage, we previously provided a Python language client for consuming the Carbon Black API on GitHub.

Well, .NET fans, your dreams have finally come true! We now have a .NET Carbon Black API client.

The source is available here.

We also created and published a NuGet package to enable quick and easy inclusion into your Visual Studio projects. As the .NET API client evolves, we will update the NuGet package so you will always have access to the latest and greatest .NET Carbon Black API client.

The NuGet package is available here.

Let’s dig in a little and see how to create a simple C# application that queries the list of “calc.exe” processes on the Carbon Black server.

In Visual Studio, create a new C# Console Application that targets .NET 4.5. Once the project template is complete, we are going to use NuGet to add a reference to the Carbon Black API .NET client by right-clicking on the Console project and selecting “Manage NuGet Packages.” This brings up the NuGet Package Manager window. We will search the online NuGet repositories for “Carbon Black.”

NETAPI

Click the “Install” button, and that’s it. The references for the Carbon Black API .NET client are now installed into our project and ready for use.

To instantiate the client, we will need three pieces of information for the constructor:

  • serverUri – this is the URI to the Carbon Black server
  • token – this is the User API Token from your profile on the Carbon Black server
  • sslVerify – a Boolean specifying whether we want to perform validation of the Carbon Black server certificates

Once we have this information, we can create the client and perform a basic query to get a list of the “calc.exe” process matches:

NETAPI2

This code will perform the search and output the formatted results to the console:

netapi3

In addition to the example above, the client contains synchronous and asynchronous client methods for performing the following RESTful operations:

GET

  • as a JSON string
  • as a Stream object
  • as a Dynamic type
  • as a Dictionary<string,object>

DELETE

POST

  • as a Dynamic type
  • as a Dictionary<string,object>

PUT

  • as a Dynamic type
  • as a Dictionary<string,object>

The Carbon Black API .NET client makes it really easy to interact with the Carbon Black server and data from .NET applications. The code on GitHub also contains a sample Console application with a few more examples. I encourage you to take a look at the code on GitHub and see how you can utilize and further extend the client to get the most out of Carbon Black.

TAGS: .NET / api / Carbon Black / NuGet / RESTful / server

Related Posts