With AlertSite Management API, you can edit email server monitors that monitor your POP3, IMAP, and SMTP servers.
To modify an email monitor, send a PATCH request with a JSON body containing the monitor configuration to the appropriate endpoint which depends on the type of your tested email server and where {id}
is the monitor ID:
Email server | Endpoint |
---|---|
IMAP | /monitors/email-imap/{id} |
POP3 | /monitors/email-pop/{id} |
SMTP | /monitors/email-smtp/{id} |
Request URL
IMAP email monitor
PATCH https://api.alertsite.com/api/v3/monitors/email-imap/{id}
POP3 email monitor
PATCH https://api.alertsite.com/api/v3/monitors/email-pop/{id}
SMTP email monitor
PATCH https://api.alertsite.com/api/v3/monitors/email-smtp/{id}
Authentication
The request must include the Authorization
header containing a user’s access token:
Authorization: Bearer ACCESS_TOKEN
See Authentication for more information.
Request body
The request body is a JSON object containing the monitor configuration fields you want to update.
For example, change the SMTP server port number and the IP address of the tested server:
{
"ipv4":"74.125.28.108"
"port":587
}
Response body
On success, the operation returns the ID of the updated monitor.
{
"id": "123456"
}
Error responses have a non-200 status code and contain the errors
list, such as:
{
"errors": [
{
"code": 400,
"message": "invalid_request - User authentication failed."
}
]
}
Try it out
Code examples
This code updates the SMTP monitor with ID 123456 and changes the port number and the IP address of the tested server:
cURL (Windows)
curl -X PATCH https://api.alertsite.com/api/v3/monitors/email-smtp/123456
-H "Authorization: Bearer ACCESS_TOKEN"
-H "Content-Type: application/json"
-d '{\"ipv4\":\"74.125.28.108\", \"port\":587}'
Note: New lines are added for readability.
The actual command should be one continuous line.
cURL (bash)
curl -X PATCH https://api.alertsite.com/api/v3/monitors/email-smtp/123456 \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "Content-type: application/json" \
-d '{"ipv4":"74.125.28.108", "port":587}'
Python
import requests # Requests library https://requests.kennethreitz.org/en/master/
import json
baseUrl = 'https://api.alertsite.com/api/v3'
username = '[email protected]' # Replace with your AlertSite login email
password = 'pa55w0rd' # Replace with your AlertSite password
monitor_params = {
'ipv4': '74.125.28.108',
'port': 587
}
# Login
payload = {'username': username, 'password': password}
r = requests.post(baseUrl+'/access-tokens', data=json.dumps(payload), headers={'Content-Type': 'application/json'})
token = r.json()['access_token']
# Update the monitor
headers = {
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json'
}
r = requests.patch(baseUrl+'/monitors/email-smtp/123456', data=json.dumps(monitor_params), headers=headers)
result = r.json()
if r.status_code == requests.codes.ok:
monitor_id = result['id']
print('Successfully updated the monitor. ID:{}'.format(monitor_id))
else:
print('Could not update the monitor. The following error(s) occurred:', *result['errors'], sep='\n')
See Also
Monitor Operations
Create an Email Server (POP/SMTP/IMAP) Monitor
Delete Monitor