Modify a Recurring Blackout

Last modified on July 26, 2024

To modify a monitor blackout or a recipient blackout, send a PATCH request to /blackouts/{id}, where {id} is the blackout ID. Only recurring (persistent) blackouts can be modified using this operation. To modify a one-time blackout, delete the existing blackout and create a new one.

Tip: To update the blackouts for multiple monitors at once, use the Bulk Edit Blackouts operation instead.

Request URL

PATCH https://api.alertsite.com/api/v3/blackouts/{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 blackout fields you want to update. You can change any of these fields: assoc_id and type (Monitor, Alert or Notifier), start_day, start_time, end_day, end_time, note.

For example, to change the blackout time to 23:30-23:55:

{
  "from_time": "23:30",
  "thru_time": "23:55"
}

Response body

On success, the operation returns HTTP status 200 with the blackout ID as a string:

{
  "id": "123456"
}

Error responses have a non-200 status code and include the errors list:

{
  "errors": [
    {
      "code": 404,
      "message": "Record not found"
    }
  ]
}

Try it out

Click here to test this operation in AlertSite’s interactive API console.

Code examples

Update the recurring blackout with ID 123456 and change its time to 23:30-23:55.

cURL (Windows)

curl -X PATCH https://api.alertsite.com/api/v3/blackouts/123456
  -H "Authorization: Bearer ACCESS_TOKEN"
  -H "Content-Type: application/json"
  -d "{\"from_time\": \"23:30\", \"thru_time\": \"23:55\"}"


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/blackouts/123456 \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{"from_time": "23:30", "thru_time": "23:55"}'

Python

# Python 3.5+
import requests  # Requests library http://docs.python-requests.org
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
blackout_id = 123456
blackout_params = {
    'from_time': '23:30',
    'thru_time': '23:55'
}

# Log in
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 blackout configuration
url = baseUrl + '/blackouts/' + str(blackout_id)
headers = {
    'Authorization': 'Bearer ' + token,
    'Content-Type': 'application/json'
}
r = requests.patch(url, data=json.dumps(blackout_params), headers=headers)
if r.status_code == requests.codes.ok:
    print('The blackout configuration has been updated.')
else:
    print('Could not update blackout #{}. The following error(s) occurred:'.format(blackout_id), *r.json()['errors'], sep='\n')

See Also

Blackout Operations

Highlight search results