Join fellow LogicMonitor users at the Elevate Community Conference and get hands-on with our latest product innovations.

Register Now

Resources

Explore our blogs, guides, case studies, eBooks, and more actionable insights to enhance your IT monitoring and observability.

View Resources

About us

Get to know LogicMonitor and our team.

About us

Documentation

Read through our documentation, check out our latest release notes, or submit a ticket to our world-class customer service team.

View Resources

Adding API Tokens

Last updated on 07 October, 2024

You can use LogicMonitor REST API v3 to add API tokens. You must authenticate yourself before making the API request.

Note: Although all POST parameters are optional for this resource, an empty payload still needs to include a set of curly braces {}.

URI: POST /setting/admins/{adminID}/apitokens

ParameterTypeDescription
adminIDInteger(Mandatory) The ID of the user for which you want to add API token.
typeStringThe default value is API token.
noteStringNote associated with the API token. Example – “note“:”John Doe’s API Token”
statusIntegerIndicates whether or not the API token is enabled. Accepted values are 1 and 2 where 1 indicates disabled and 2 indicates enabled.

The following Python script adds a set of API tokens for user with ID 32.

#!/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 ='POST'
resourcePath = '/setting/admins/32/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.post(url, data=data, headers=headers)
 
# Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)
Python 3

Get Started with LogicMonitor