REST API Developer's Guide

Get Roles

You can use LogicMonitor's REST API to programmatically get information about your LogicMonitor roles. You can either get a list of roles or you can get details for a particular role.

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

 

Get a list of all Roles

Returns a list of roles

HTTP Method: GET

URI: /setting/roles

Request Parameters: By default, a list of 50 roles will be returned. You can include sort, filter, fields, size and offset parameters in your request to control what data is included in the response and how it is formatted.

Property

Syntax

Description

Example URI

sort sort={+ or -}property Sorts the response by the property specified in either increasing (+) or decreasing (-) order /setting/roles?sort=-id
filter filter=property{operator}value Filters the response according to the operator and value specified. Note that you can use * to match on more than one character.You can use the '.' character to filter values within an object (e.g. custom properties), and multiple filters can be separated by a comma.

Operators include:
  • Greater than or equals: >:
  • Less than or equals: <:
  • Greater than: >
  • Less than: <
  • Does not equal: !:
  • Equals: :
  • Includes: ~
  • Does not include: !~
/setting/roles?filter=name:administrator
fields fields={list of properties separated by commas} Filters the response to only include the following fields for each object /setting/roles?fields=name,privileges
size size=integer The number of results to display /setting/roles?size=5
offset offset=integer The number of results to offset the displayed results by /setting/roles?offset=2

 

Example 1: GET all Roles

The following Python script will return a list of all roles in the api.logicmonitor.com portal. 

#!/bin/env python

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

#Account Info
AccessId ='48v2wRzfK94y53sq5EuF'
AccessKey ='H_D9i(f5~B^U36^K6i42=^nS~e75gy382Bf6{)P+'
Company = 'api'

#Request Info
httpVerb ='GET'
resourcePath = '/setting/roles'
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
 

 

Example 2: GET all Roles

The following Python script will return a list of roles in the api.logicmonitor.com portal, where only the name, associatedUserCount and privileges are returned for each result and the results are sorted in descending order according to the associatedUserCount. 

#!/bin/env python

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

#Account Info
AccessId ='48v2wRzfK94y53sq5EuF'
AccessKey ='H_D9i(f5~B^U36^K6i42=^nS~e75gy382Bf6{)P+'
Company = 'api'

#Request Info
httpVerb ='GET'
resourcePath = '/setting/roles'
queryParams = '?fields=name,associatedUserCount,privileges&sort=-associatedUserCount'
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 

 

Get information about a particular role

Returns details for a particular role

HTTP Method:GET

URI: /setting/roles/{id}

Request Parameters: You can include a filter parameter that controls which properties are displayed in the response:

Property

Syntax

Description

Example URI

fields fields={list of properties separated by commas} Filters the response to only include the following fields for each object /setting/roles/{id}?fields=name,associatedUserCount

 

Example 1: GET one role

The following Python script will return the details for the role with id 8. 

#!/bin/env python

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

#Account Info
AccessId ='48v2wRzfK94y53sq5EuF'
AccessKey ='H_D9i(f5~B^U36^K6i42=^nS~e75gy382Bf6{)P+'
Company = 'api'

#Request Info
httpVerb ='GET'
resourcePath = '/setting/roles/8'
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