Forum Discussion
Dave_Lee - I am confident with working APIs directly. Please guide me with API that can be executed from local windows laptop to fetch device id against a given device name.
Need your help for Step-2 and Step-3. Let's start with Step-2 first.
Step-1
AccessID and AccessKey created.
Step-2
Execute API to fetch deviceID ( let say deviceName=ABC)
Step-3
Execute API to delete Device using fetched deviceID
- Dave_Lee26 days ago
Advisor
LogicMonitor provide the following documentation for their API endpoints. They documented it using Swagger, so should be familiar as it's a fairly common API documentation framework. https://www.logicmonitor.com/swagger-ui-master/dist/#/Devices
Hopefully the following will give you a steer in the right direction. For me, it was generating the signature for the authentication header that caused me the most problems. You might want to look at using a Bearer token rather than AccessId/AccessKey (aka LMv1 token) as the Bearer token is much easier to use.
For step-2
You call the device/devices API and pass in a filter to narrow down your search to a specific device. This page provides examples of how to structure filters in your API call: https://www.logicmonitor.com/support/rest-api-basic-filters
The section headed up "Filters for /device/devices API Endpoints" shows some examples of the filters that you can use. For example, if you want to use displayname, you can do a GET request like thi
https://<account>.logicmonitor.com/device/devices?filter=displayName~"*Member"
If found, this will return a JSON payload with information about the device, including it's ID. You'll need to parse the JSON output to get the ID for the device.
If you know the device ID already, you could bypass this step and go straight to the delete API call. All you need is the device ID.
For step-3
Now you can make an DELTE request to the device/devices endpoint, passing in the ID of the device to delete the device
https://<account>.logicmonitor.com/device/devices/18904
Authentication / Headers
You should add the following headers for all requests:- X-Version = 3
- Content-Type = application/json
- Authorization = <token>
For authentication, given that you want to use the AccessID and AccessKey method, you are using the "LMv1 Token" authentication method (not related to the API version, this works fine for API v3). You will have to construct the value of <token> including "LMv1 ", then your Access ID, then a Base64 encoded signature generated from your access key and the details of your request, followed by a timestamp.
You should end up with something in the following format
LMv1 AccessId:Signature:Timestamp
This page will give you some guidance on how to construct this. Exactly how you do this will depend on the system/language you are using. https://www.logicmonitor.com/support/rest-api-authentication
Alternatively, an easier option is to generate a Bearer token on your account. You can then provide this bearer token direction in the Authorization header, without having to mess about with having to generate a signature etc.
- Dave_Lee20 days ago
Advisor
Hi pranshulgarg - did this help at all? Do you need anything else?
Dave