As the title suggests, I've been playing around with webhooks and would like to take action on them. My issue is, there is no flag/field that denotes that this is a new incident being created for the first time.
1) That would be a great feature to have added
2) Are there any suggestions on using the webhook and knowing if it's the first time an incident is being created?
Hey @Jordan Violet Happy to help :)
You should be able to use the Statuspage API to fetch incident details and determine if an incident is new or not.
When you receive a webhook, you can use the incident ID from the webhook payload to fetch incident details using the API.
I would say this is a suggestion, as we don't have a code, and this is done on your side.
Here's how you should be able to do it:
1. Make an API call to the following endpoint to get incident details:
`GET https://api.statuspage.io/v1/pages/:page_id/incidents/:incident_id`
Replace `:page_id` with your Statuspage page ID and `:incident_id` with the incident ID from the webhook payload.
2. Check the `created_at` and `updated_at` fields in the API response, just like in the webhook payload approach.
Here's a Python example using the `requests` library:
```python
import requests
import datetime
page_id = "your_page_id"
incident_id = "incident_id_from_webhook"
api_key = "your_api_key"
url = f"https://api.statuspage.io/v1/pages/{page_id}/incidents/{incident_id}"
headers = {"Authorization": f"OAuth {api_key}"}
response = requests.get(url, headers=headers)
incident_data = response.json()
created_at = datetime.datetime.strptime(incident_data['created_at'],
'%Y-%m-%dT%H:%M:%SZ')
updated_at = datetime.datetime.strptime(incident_data['updated_at'], '%Y-%m-%dT%H:%M:%SZ')
if (updated_at - created_at).total_seconds() < 5: # Considering a 5-second difference
print("New incident")
else:
print("Existing incident")
```
Replace `your_page_id`, `incident_id_from_webhook`, and `your_api_key` with the appropriate values.
This approach should give you more control over the incident data and allow you to access additional information that might not be available in the webhook payload.
However, it requires an additional API call, which might increase processing time and consume API rate limits.
If the webhook payload provides enough information to determine if an incident is new or not, using the API might not be necessary.
In case you have further question or if you need further troubleshooting, I would recommend you open a formal ticket with our support here, Jordan. 😄
https://support.atlassian.com/contact/#/
Best,
Rafa
Hey Rafa,
Great writeup and I appreciate the well-thought answer. The issue with this solution and having to make an additional API call though is that turns this into polling and really defeats the value of a webhook.
It would make much more sense that the webhook simply had an additional boolean/string value indicating if this was a new incident or an incident update, especially considering the implementation behind the webhook likely already has this information. Where could one submit a feature request for a simple addition like this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for the suggestion @Jordan Violet
I have created the Feature Request, you won't be able to open it, since it is internal, but you can have the reference name: STATUS-576.
I have attached this community question to it, and we will let you know of any progress.
I really appreciate it.
If you have any further questions, let me know.
Best,
Rafa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You're welcome!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.