Untitled
unknown
plain_text
2 years ago
1.3 kB
4
Indexable
Sure, here's an example of how you can use PagerDuty API to create an incident: ```python import requests import json # set up the endpoint URL url = "https://api.pagerduty.com/incidents" # set up the authentication headers headers = { "Accept": "application/vnd.pagerduty+json;version=2", "Content-Type": "application/json", "Authorization": "Token token=YOUR_API_KEY", } # set up the payload for the incident payload = { "incident": { "type": "incident", "title": "Example Incident", "service": { "id": "SERVICE_ID", "type": "service_reference" }, "incident_key": "incident-123", "body": { "type": "incident_body", "details": "This is an example incident." } } } # send the POST request to create the incident response = requests.post(url, headers=headers, data=json.dumps(payload)) # check the response status code if response.status_code == 201: print("Incident created successfully.") else: print("Incident creation failed. Status code: ", response.status_code) ``` Please note that you need to replace the `YOUR_API_KEY` and `SERVICE_ID` with your actual PagerDuty API key and service ID respectively. You can find your API key and service ID in your PagerDuty account settings.
Editor is loading...