Getting API Token Details
Last updated on 07 October, 2024You can use LogicMonitor REST API v3 to get API token details. You must authenticate yourself before making the API request.
Getting List of API Tokens Across Users
You can include the following query parameters to manage the kind of data to include in the response and how it is formatted.
Note: Query parameters are not part of the resource path, and should not be included in the calculation of the LMv1 authentication signature.
URI: GET/setting/admins/apitokens
Parameter | Type | Description |
type | String | Returns a list of API bearer tokens. If you don’t enter a value for the type parameter, then by default it returns a list of LMv1 API tokens.Example – /setting/admins/apitokens?type=bearer |
permission | String | Filters a list of bearer tokens of users who have permission to traces.If you don’t enter value for the permission parameter, then by default it returns a list of all bearer tokens. However, if you specify permission=traces, then it returns a list of bearer tokens generated by users who have permission to traces.Example – /setting/admins/apitokens?permission=traces&type=bearer |
fields | String | The response is filtered to include only the specified fields for each object. You can provide a list of properties separated by a comma. Example – /setting/admins/apitokens?fields=id,status,adminName |
size | Integer | Indicates the number of results to display. A maximum of 1000 results can be requested in a GET call. By default, a list of 50 API tokens is returned if a value is not provided for this parameter. Example – /setting/admins/apitokens?size=5 |
offset | Integer | Indicates the number of results to offset the displayed results. By default, offset is set to 0. Example – /setting/admins/apitokens?offset=2 |
filter | String | The response is filtered according to the operator and specified value that is, filter=property:value
Operators include:
/setting/admins/apitokens?filter=status:2 |
The following Python script gets all API tokens in the account api.logicmonitor.com.
#!/bin/env python
import requests
import json
import hashlib
import base64
import time
import hmac
import getpass
#Account Info: LogicMonitor recommends to NEVER hardcode the credentials. Instead, retrieve the values from a secure storage.
#Note: The below is provided for illustration purposes only.
AccessId = getpass.getpass("Enter your AccessId: ")
AccessKey = getpass.getpass("Enter your AccessKey: ")
Company = 'apiAccount'
#Request Info
httpVerb ='GET'
resourcePath = '/setting/admins/apitokens'
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
digest = hmac.new(
AccessKey.encode('utf-8'),
msg=requestVars.encode('utf-8'),
digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(digest.encode('utf-8')).decode('utf-8')
#Construct headers
auth = 'LMv1 ' + AccessId + ':' + str(signature) + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth,'X-Version':'3'}
# 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)
Getting List of API Tokens
URI: GET /setting/admins/{adminId}/apitokens
The query parameters: type
, permission
, fields
, size
, offset
, and filter
should also be included while making the request GET /setting/admins/{adminId}/apitokens
. Please refer the table in the section Getting list of API tokens across users for details about the query parameters.
An additional parameter adminId
which is specific to /setting/admins/{adminId}/apitokens
is described in the following table.
Parameter | Type | Description |
adminId | Integer | (Mandatory) The ID of the user for which you want to get API tokens. |
The following Python script gets all API tokens for user with ID 131 in account api.logicmonitor.com.
#!/bin/env python
import requests
import json
import hashlib
import base64
import time
import hmac
import getpass
#Account Info: LogicMonitor recommends to NEVER hardcode the credentials. Instead, retrieve the values from a secure storage.
#Note: The below is provided for illustration purposes only.
AccessId = getpass.getpass("Enter your AccessId: ")
AccessKey = getpass.getpass("Enter your AccessKey: ")
Company = 'apiAccount'
#Request Info
httpVerb ='GET'
resourcePath = '/setting/admins/131/apitokens'
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
digest = hmac.new(
AccessKey.encode('utf-8'),
msg=requestVars.encode('utf-8'),
digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(digest.encode('utf-8')).decode('utf-8')
#Construct headers
auth = 'LMv1 ' + AccessId + ':' + str(signature) + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth,'X-Version':'3'}
# 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)