Skip to content

Tag: API

Learn Log Insight’s REST API with Postman!

Getting started with a new API is always… interesting. Here lately, I have found myself getting a lot better acquainted with Log Insight. If you’ve never heard of it, this is a log management solution from VMware.

Anyways, when I first start using an API I like to read through the docs and try some basic calls. Log Insight’s API documentation is pretty solid. However, when it turned time to start actually making some calls, I then had a wealth of tools at my disposal to make calls. This is a good problem to have!

I’m still new to this API, so I’m looking for the path of least resistance. Enter the Postman, a free REST Client. My favorite part of Postman is the ability to use Collections. These Postman Collections are literal collections of API calls that can then be exported/imported and shared.

I created a Log Insight collection and have shared it on GitHub: Log Insight Postman Collection

Prepping the Client

Prerequisite: Have the Postman desktop client installed. (I haven’t tested this in the Chrome app)

We can start using this collection by heading out to my GitHub Repository and downloading it in your preferred method. For this example, I’ll be downloading it as a ZIP file.

Download GitHub Repo

Extract the ZIP to a location of your choosing.

Open Postman, click the “Import” box (alternatively, File -> Import)

Import Postman Collection to Client

Select the “Log Insight.postman_collection.json” file

Select appropriate JSON file

We will see a new folder titled “Log Insight” which contains 49 requests:

Sample Collection View

Preparing Environmental Variables

Another great reason to use Postman is the ability to use environmental variables. I highly recommend using these as it will greatly simplify the experience.

We will need to create the following variables:

  • li – this will be the Log Insight node we’ll be making calls against
  • auth – this is the authorization string that is referenced in each call’s header

To create these variables, we’ll need to go to the gear icon towards the top right corner and select “Manage Environments”

Manage Environments Option

On the “Manage Environments” section, click “Add”

Manage Environments Layout

We can then give the environment a name and start filling in those variables I listed above (since we do not yet have a Session ID, the auth variable will be left blank), then click “Add”

Log Insight Demo Environment Setup

We can now close out of the “Manage Environments” section by clicking on the “X”

We now want to configure Postman to reference these variables. To do this, we will select the “Environment” dropdown box and select the environment we just created.

Choosing to use the new Log Insight Demo Environment

Authenticating

The first call we’ll want to perform is to authenticate to the Log Insight node and receive our Session ID.

To do this select the “Sessions” folder, then click on the “Login” request.

Exploring the Session Login Request

We’ll now select the “Body” tab. Here we’ll see a preformed body in JSON format. Modify the values to match that of your environment.

Exploring a sample body

We can now click “Send” to actually perform the API call

Example response

If all goes well, you’ll receive a status of “200 OK” and a result like the above.

Now that we have our session ID, we’ll need to fill in our “auth” variable so that we can start easily using the Log Insight API.

Copy the sessionId value within the quotations and head back to the “Manage Environment” section.

Click on the Environment we created earlier, then click into the “Value” section for the “auth” variable:

Update Environmental Variables

Referencing the Log Insight API documentation on authentication, for the Authorization variable we will want to type “Bearer” followed by a space and then the sessionId value

Example Auth variable for the Environment

Click “Update” then close out of the “Manage Environment” section by clicking on the “X” in the top right corner

Making Log Insight API Calls

At this point we have our Postman Collection imported, our session is authenticated, and our variables are set! We can now start making calls to the Log Insight node.

Example: Finding out what authentication providers are available

Select the “Auth-Providers” folder, click “List”, then click “Send”

Auth Providers Sample Response

Example: Obtaining a list of Events

Select the “Events” folder, click “List”, then click “Send”

Sample Events List Response

One Last Thing

There’s a couple areas where appears to be a variable, but it’s not one that we’ve configured.

Example: Within the “Licenses” folder there’s a “Remove” request.

Clicking on the request gives us the following for the request URL:

Exploring License Removal Request

Noting the “{license}” portion of the URL, this section is supposed to be overwritten with an actual value. If we reference the above screenshot, we can see that there is an “Example” we can refer to (top right corner, beneath the “Manage Environments” icon).

Clicking on that example button will take us to an example of what the call will look like along with a sample response.

Exploring License Removal Request Example

Wrap-Up

Getting started using an API can be a lot of things. This Postman Collection should be a great resource to start learning and using the Log Insight API. I know I learned a lot by creating and using it. If there’s any suggestions or additional examples you’d like to see, please submit an Issue against the repo with those notes. Better yet, contribute back by forking the repo and creating a pull request with those updates!