REST API Developer's Guide

Run a Report

With LogicMonitor's REST API you can programmatically run a report & query existing report execution tasks for large reports.

 Note: As with all of our API calls, authentication is required.

Run a Report

HTTP Method:POST

URI: /functions

Request Parameters:

Property

Description

Required?

Type

Example

type This value needs to be generateReport Yes String "type":"generateReport"
reportId The Id of the report you'd like to run Yes Integer "reportId":27
receiveEmails A comma separated list of email addresses that should be notified once the report has been generated. A link to the report will be included in the notification email, but not in the API response if this query parameter is specificed. No String "receiveEmails":"sarah.terry@logicmonitor.com"

Example Request

The following Python script will run the report with id 27 in the api.logicmonitor.com account.

#!/bin/env python

import requests
import json
import hashlib
import base64
import time
import hmac

#Account Info
AccessId ='YQQ75w6Mxx9zWIeAMq5H'
AccessKey ='f)!Z}%spR=6en+4^s2$t32r-3=NpdQ]2T{-deI)8'
Company = 'api'

#Request Info
httpVerb ='POST'
resourcePath = '/functions'
data = '{"type":"generateReport","reportId":27}'

#Construct URL 
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath 

#Get current time in milliseconds
epoch = str(int(time.time() * 1000))

#Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath

print requestVars

#Construct signature
signature = base64.b64encode(hmac.new(AccessKey,msg=requestVars,digestmod=hashlib.sha256).hexdigest())

#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth}

#Make request
response = requests.post(url, data=data, headers=headers)

#Print status and body of response
print 'Response Status:',response.status_code
print 'Response Body:',response.content

 

Get a URL for an existing Report execution task

HTTP Method:GET

URI: /report/reports/REPORT_ID/tasks/TASK_ID

Where REPORT_ID is the id of the report, and TASK_ID is the id of the task you're wanting to get a report URL for (returned when you run the report).

Example Request

The following Python script will request the URL for task 6041259673900733970 for report 1 in the api.logicmonitor.com account.

#!/bin/env python

import requests
import json
import hashlib
import base64
import time
import hmac

#Account Info
AccessId ='YQQ75w6Mxx9zWIeAMq5H'
AccessKey ='f)!Z}%spR=6en+4^s2$t32r-3=NpdQ]2T{-deI)8'
Company = 'api'

#Request Info
httpVerb ='GET'
resourcePath = '/report/reports/1/tasks/6041259673900733970'
queryParams = ''
data=''

#Construct URL
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath + queryParams

#Get current time in milliseconds
epoch = str(int(time.time() * 1000))

#Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath

#Construct signature
signature = base64.b64encode(hmac.new(AccessKey,msg=requestVars,digestmod=hashlib.sha256).hexdigest())

#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth}

#Make request
response = requests.get(url, data=data, headers=headers) #Print status and body of response print 'Response Status:',response.status_code print 'Response Body:',response.content