REST API v1 Examples
The following examples illustrate LMv1 Authentication for v1 of the LogicMonitor API:
- Python 2.7 POST Example
- Python 2.7 GET Example
- Python 3 GET Example
- Groovy GET Example
- Groovy PUT Example
- PowerShell GET Example
- PowerShell POST Example
- Ruby GET Example
- Ruby POST Example
- PHP POST Example
- Node.js GET Example
- Python 2.7 cURL Tool Example
Example 1 – Python 2.7 POST
The following script illustrates LMv1 Authentication for a POST request in Python (version 2.7). Specifically, the following request adds a service to the account apiAccount.logicmonitor.com:
Example 2 – Python 2.7 GET
The following script illustrates LMv1 Authentication for a GET request in Python (version 2.7). Specifically, the following request gets details for all services in apiAccount.logicmonitor.com:
Example 3 – Python 3 GET
The following script illustrates LMv1 Authentication for a GET request in Python (version 3.5). Specifically, the following request gets details for all devices in apiAccount.logicmonitor.com:
Example 4 – Groovy GET
The following script illustrates LMv1 Authentication for a GET request in Groovy. Specifically, the following request gets details for all services in apiAccount.logicmonitor.com:
Example 5 – Groovy PUT
The following script illustrates LMv1 Authentication for a PUT request in Groovy. Specifically, the following request updates a device in account apiAccount.logicmonitor.com:
Example 6 – PowerShell GET
The following script illustrates LMv1 Authentication for a GET request in PowerShell. Specifically, the following request gets details for all services in apiAccount.logicmonitor.com:
Example 7 – PowerShell POST
The following script illustrates LMv1 Authentication for a POST request in PowerShell. Specifically, the following request adds a service in apiAccount.logicmonitor.com:
Example 8 – Ruby GET
The following script illustrates LMv1 Authentication for a GET request in Ruby. Specifically, the following request gets details for all services in api.logicmonitor.com:
Example 9 – Ruby POST
The following script illustrates LMv1 Authentication for a POST request in Ruby. Specifically, the following request adds a service in api.logicmonitor.com:
Example 10 – PHP POST
The following script adds an alert rule to account api.logicmonitor.com:
Example 11 – Node.js GET
The following script gets the name and id of all devices with “prod” in the name from account api.logicmonitor.com:
What if I want to make a cURL request?
Because LMv1 API Token Authentication is a bit more complicated than Basic Auth, it is more difficult to use in a cURL command or other one line request. If you’d like to make a one line request, consider using a script like the below that allows you to do so.
This particular example script should be used like this:
python scriptName.py --id --key --method --url --data [Request Payload]
where < > denotes a required parameter and [ ] denotes an optional parameter
For example, the following command may be made from a terminal and uses the above script to retrieve all services in api.logicmonitor.com