How to handle GRID Support notifications automatically in your code
Article 4046883, Status: VALIDATED
Table of Contents
❓ Issue/Question
- How can I parse GRID ops channel messages automatically?
- How do I extract the JSON from a GRID Support notification?
- Can I handle GRID notifications programmatically instead of reading them?
🖥️ Environment/Context
- GRID Support notifications in your dedicated ops channel
👌 Resolution/Answer
- Take the full message text.
- Find the last line that starts with
{. The JSON block starts there and runs to the end of the message. - Parse it as JSON.
- Branch on
grid_event, and useseriesIDto match the notification to the series in your system. - Read optional keys only if they are present. Only
grid_event,seriesID,matchandtournamentare always there.
Python example
import json
def parse_grid_notification(text: str) -> dict:
start = text.rfind("\n{")
if start == -1:
raise ValueError("No JSON block found")
return json.loads(text[start + 1:])
event = parse_grid_notification(message_text)
if event["grid_event"] == "Series_Recreation":
link_series(event["seriesID"], event.get("new_seriesID"))
elif event["grid_event"] in ("Reschedule", "Reschedule_Unkown_Date"):
update_schedule(event["seriesID"], event.get("new_date"), event.get("new_time"))
-
link_seriesandupdate_schedulestand in for your own functions. - Handle
grid_eventvalues you don't recognise without failing, so a new notification type can't break your integration.
🗒️Scratch Pad
For the keys and all grid_event values, see How to read the JSON in GRID Support notifications and How to tell why GRID Support sent a notification (grid_event values).