Accessing the LogicMonitor REST API with Postman and Bearer Token Authentication
This is a follow-up to the classic Kurt_Huffman post: Accessing the LogicMonitor REST API with Postman and LMv1 API Token Authentication | LogicMonitor - 5143
That post is still a treasure trove of good discussion. Definitely check it out if you haven't already! While there is passing mention that you can use bearer token auth in Postman, I figured I'd write up a dedicated post.
Creating a bearer token
With the addition of bearer tokens, we eliminate the need for a Base64 encoded HMAC signature – so we get rid of several steps for auth. No need for any pre-request script, yay!
See this page for generating and using bearer tokens in LogicMonitor: https://www.logicmonitor.com/support/bearer-token
We do have a section in the above page on using the bearer token with Postman, but I like setting up with environment variables for better reusability.
Postman setup with bearer tokens
- Download and install Postman, or use http://postman.com
- Launch Postman and create a new collection that will be used for all LogicMonitor API requests.
- Create a new environment with the following variable. You just need one for the bearer token. You should set the type to 'secret' for sensitive credentials.
- url – https://<portalname>.logicmonitor.com/santaba/rest
- If you want to work with the LM Ingestion API, duplicate this environment and change the url to 'https://<portalname>.logicmonitor.com/rest' (without "santaba")
- bearer – secret – For the current value, be sure to prepend the token with "bearer " (with space)
- Should look like this: bearer lmb_xxx
- url – https://<portalname>.logicmonitor.com/santaba/rest
- Create a request within the collection. A sample request is shown below with the necessary parameters configured.
- Set the environment for the request (from step 3)
- Set the HTTP method for the request
- Use {{url}} to pull the base URL from the environment variable. Add the resource path and any request parameters your API request may require.
- Add the following headers:
- Authorization: {{bearer}}
- X-version: 3 (for latest LM API version)
- POST, PUT, and PATCH requests only: if your request includes JSON data, be sure to select the Body tab and select raw JSON