├── EVENTS_API_V1 ├── Resolve │ └── resolve_incident.py ├── Trigger │ ├── trigger_with_incident_key.py │ └── trigger_without_incident_key.py └── ack │ └── ack_incident.py ├── EVENTS_API_v2 ├── ack │ └── ack_incident.py ├── resolve │ └── resolve_incident.py └── trigger │ ├── trigger_with_incident_key.py │ └── trigger_without_incident_key.py └── REST_API_v2 ├── Abilities ├── list_abilities.py └── test_ability.py ├── AddOns ├── delete_addon.py ├── get_addon.py ├── install_addon.py ├── list_installed_addons.py └── update_addon.py ├── EscalationPolicies ├── create_escalation_policy.py ├── delete_escalation_policy.py ├── get_escalation_policy.py ├── list_escalation_policies.py └── update_escalation_policy.py ├── Incidents ├── create_incident_note.py ├── get_incident.py ├── list_incident_log_entries.py ├── list_incident_notes.py ├── list_incidents.py ├── manage_incidents.py ├── snooze_incident.py ├── trigger_incident.py └── update_incident.py ├── LogEntries ├── get_log_entry.py └── list_log_entries.py ├── MaintenanceWindows ├── create_maintenance_window.py ├── create_maintenance_window_all_services.py ├── delete_or_end_maintenance_window.py ├── end_all_maintenance_windows.py ├── get_maintenance_window.py ├── list_maintenance_windows.py └── update_maintenance_window.py ├── Notifications └── list_notifications.py ├── OnCalls └── list_oncalls.py ├── Schedules ├── create_override.py ├── create_schedule.py ├── delete_override.py ├── delete_schedule.py ├── get_schedule.py ├── list_oncall_users.py ├── list_overrides.py ├── list_schedules.py ├── preview_schedule.py └── update_schedule.py ├── Services ├── create_integration.py ├── create_service.py ├── delete_service.py ├── get_integration.py ├── get_service.py ├── list_services.py ├── update_integration.py └── update_service.py ├── Teams ├── add_escalation_policy_to_team.py ├── add_user_to_team.py ├── create_team.py ├── delete_team.py ├── get_team.py ├── list_teams.py ├── remove_escalation_policy_from_team.py ├── remove_user_from_team.py └── update_team.py ├── Users ├── create_user.py ├── create_user_contact_method.py ├── create_user_notification_rule.py ├── delete_user.py ├── delete_user_contact_method.py ├── delete_user_notification_rule.py ├── get_user.py ├── get_user_contact_method.py ├── get_user_notification_rule.py ├── list_user_contact_methods.py ├── list_user_notification_rules.py ├── list_users.py ├── update_user.py ├── update_user_contact_method.py └── update_user_notification_rule.py └── Vendors ├── get_vendor.py └── list_vendors.py /EVENTS_API_V1/Resolve/resolve_incident.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import json 4 | import requests 5 | 6 | SERVICE_KEY = "" # ENTER EVENTS V1 API INTEGRATION KEY HERE 7 | INCIDENT_KEY = "" # ENTER INCIDENT KEY 8 | 9 | def resolve_incident(): 10 | # Triggers a PagerDuty incident without a previously generated incident key 11 | # Uses Events V1 API - documentation: https://v2.developer.pagerduty.com/docs/trigger-events 12 | 13 | payload = { # Payload is built with the least amount of fields required to trigger an incident 14 | "service_key": SERVICE_KEY, 15 | "event_type": "resolve", 16 | "incident_key": INCIDENT_KEY, 17 | "description": "Example alert on host1.example.com" 18 | } 19 | 20 | response = requests.post('https://events.pagerduty.com/generic/2010-04-15/create_event.json', 21 | data=json.dumps(payload)) 22 | 23 | if response.json()["status"] == "success": 24 | print ('Incident Resolved') 25 | else: 26 | print(response.text) # print error message if not successful 27 | 28 | if __name__ == '__main__': 29 | resolve_incident() 30 | -------------------------------------------------------------------------------- /EVENTS_API_V1/Trigger/trigger_with_incident_key.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import json 4 | import requests 5 | 6 | SERVICE_KEY = "" # ENTER EVENTS V1 API INTEGRATION KEY HERE 7 | INCIDENT_KEY = "" # ENTER INCIDENT KEY 8 | 9 | def trigger_incident(): 10 | # Triggers a PagerDuty incident without a previously generated incident key 11 | # Uses Events V1 API - documentation: https://v2.developer.pagerduty.com/docs/trigger-events 12 | 13 | payload = { # Payload is built with the least amount of fields required to trigger an incident 14 | "service_key": SERVICE_KEY, 15 | "event_type": "trigger", 16 | "incident_key": INCIDENT_KEY, 17 | "description": "Example alert on host1.example.com" 18 | } 19 | 20 | response = requests.post('https://events.pagerduty.com/generic/2010-04-15/create_event.json', 21 | data=json.dumps(payload)) 22 | 23 | if response.json()["status"] == "success": 24 | print('Incident Triggered') 25 | else: 26 | print(response.text) # print error message if not successful 27 | 28 | if __name__ == '__main__': 29 | trigger_incident() 30 | -------------------------------------------------------------------------------- /EVENTS_API_V1/Trigger/trigger_without_incident_key.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import json 4 | import requests 5 | 6 | SERVICE_KEY = "" # ENTER EVENTS V1 API INTEGRATION KEY HERE 7 | 8 | def trigger_incident(): 9 | # Triggers a PagerDuty incident without a previously generated incident key 10 | # Uses Events V1 API - documentation: https://v2.developer.pagerduty.com/docs/trigger-events 11 | 12 | payload = { # Payload is built with the least amount of fields required to trigger an incident 13 | "service_key": SERVICE_KEY, 14 | "event_type": "trigger", 15 | "description": "Example alert on host1.example.com" 16 | } 17 | 18 | response = requests.post('https://events.pagerduty.com/generic/2010-04-15/create_event.json', 19 | data=json.dumps(payload)) 20 | 21 | if response.json()["status"] == "success": 22 | print('Incident created with with incident / alert key of ' + '"' + response.json()['incident_key'] + '"') 23 | else: 24 | print(response.text) # print error message if not successful 25 | 26 | if __name__ == '__main__': 27 | trigger_incident() 28 | -------------------------------------------------------------------------------- /EVENTS_API_V1/ack/ack_incident.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import json 4 | import requests 5 | 6 | SERVICE_KEY = "" # ENTER EVENTS V1 API INTEGRATION KEY HERE 7 | INCIDENT_KEY = "" # ENTER INCIDENT KEY 8 | 9 | def ack_incident(): 10 | # Triggers a PagerDuty incident without a previously generated incident key 11 | # Uses Events V1 API - documentation: https://v2.developer.pagerduty.com/docs/trigger-events 12 | 13 | payload = { # Payload is built with the least amount of fields required to trigger an incident 14 | "service_key": SERVICE_KEY, 15 | "event_type": "acknowledge", 16 | "incident_key": INCIDENT_KEY, 17 | "description": "Example alert on host1.example.com" 18 | } 19 | 20 | response = requests.post('https://events.pagerduty.com/generic/2010-04-15/create_event.json', 21 | data=json.dumps(payload)) 22 | 23 | if response.json()["status"] == "success": 24 | print('Incident Acknowledged') 25 | else: 26 | print(response.text) # print error message if not successful 27 | 28 | if __name__ == '__main__': 29 | ack_incident() 30 | -------------------------------------------------------------------------------- /EVENTS_API_v2/ack/ack_incident.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import json 4 | import requests 5 | 6 | ROUTING_KEY = "" # ENTER EVENTS V2 API INTEGRATION KEY HERE 7 | INCIDENT_KEY = "" # ENTER INCIDENT KEY HERE 8 | 9 | def ack_incident(): 10 | # Triggers a PagerDuty incident without a previously generated incident key 11 | # Uses Events V2 API - documentation: https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2 12 | 13 | header = { 14 | "Content-Type": "application/json" 15 | } 16 | 17 | payload = { # Payload is built with the least amount of fields required to trigger an incident 18 | "routing_key": ROUTING_KEY, 19 | "event_action": "acknowledge", 20 | "dedup_key": INCIDENT_KEY 21 | } 22 | 23 | response = requests.post('https://events.pagerduty.com/v2/enqueue', 24 | data=json.dumps(payload), 25 | headers=header) 26 | 27 | if response.json()["status"] == "success": 28 | print('Incident Acknowledged ') 29 | else: 30 | print(response.text) # print error message if not successful 31 | 32 | if __name__ == '__main__': 33 | ack_incident() 34 | -------------------------------------------------------------------------------- /EVENTS_API_v2/resolve/resolve_incident.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import json 4 | import requests 5 | 6 | ROUTING_KEY = "" # ENTER EVENTS V2 API INTEGRATION KEY HERE 7 | INCIDENT_KEY = "" # ENTER INCIDENT KEY HERE 8 | 9 | def resolve_incident(): 10 | # Triggers a PagerDuty incident without a previously generated incident key 11 | # Uses Events V2 API - documentation: https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2 12 | 13 | header = { 14 | "Content-Type": "application/json" 15 | } 16 | 17 | payload = { # Payload is built with the least amount of fields required to trigger an incident 18 | "routing_key": ROUTING_KEY, 19 | "event_action": "resolve", 20 | "dedup_key": INCIDENT_KEY 21 | } 22 | 23 | response = requests.post('https://events.pagerduty.com/v2/enqueue', 24 | data=json.dumps(payload), 25 | headers=header) 26 | 27 | if response.json()["status"] == "success": 28 | print('Incident Resolved ') 29 | else: 30 | print(response.text) # print error message if not successful 31 | 32 | if __name__ == '__main__': 33 | resolve_incident() 34 | -------------------------------------------------------------------------------- /EVENTS_API_v2/trigger/trigger_with_incident_key.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import json 4 | import requests 5 | 6 | ROUTING_KEY = "" # ENTER EVENTS V2 API INTEGRATION KEY HERE 7 | INCIDENT_KEY = "" # ENTER INCIDENT KEY HERE 8 | 9 | def trigger_incident(): 10 | # Triggers a PagerDuty incident without a previously generated incident key 11 | # Uses Events V2 API - documentation: https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2 12 | 13 | header = { 14 | "Content-Type": "application/json" 15 | } 16 | 17 | payload = { # Payload is built with the least amount of fields required to trigger an incident 18 | "routing_key": ROUTING_KEY, 19 | "event_action": "trigger", 20 | "dedup_key": INCIDENT_KEY, 21 | "payload": { 22 | "summary": "Example alert on host1.example.com", 23 | "source": "monitoringtool:cloudvendor:central-region-dc-01:852559987:cluster/api-stats-prod-003", 24 | "severity": "critical" 25 | } 26 | } 27 | 28 | response = requests.post('https://events.pagerduty.com/v2/enqueue', 29 | data=json.dumps(payload), 30 | headers=header) 31 | 32 | if response.json()["status"] == "success": 33 | print('Incident Created') 34 | else: 35 | print(response.text) # print error message if not successful 36 | 37 | if __name__ == '__main__': 38 | trigger_incident() 39 | -------------------------------------------------------------------------------- /EVENTS_API_v2/trigger/trigger_without_incident_key.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import json 4 | import requests 5 | 6 | ROUTING_KEY = "" # ENTER EVENTS V2 API INTEGRATION KEY HERE 7 | 8 | def trigger_incident(): 9 | # Triggers a PagerDuty incident without a previously generated incident key 10 | # Uses Events V2 API - documentation: https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2 11 | 12 | header = { 13 | "Content-Type": "application/json" 14 | } 15 | 16 | payload = { # Payload is built with the least amount of fields required to trigger an incident 17 | "routing_key": ROUTING_KEY, 18 | "event_action": "trigger", 19 | "payload": { 20 | "summary": "Example alert on host1.example.com", 21 | "source": "monitoringtool:cloudvendor:central-region-dc-01:852559987:cluster/api-stats-prod-003", 22 | "severity": "critical" 23 | } 24 | } 25 | 26 | response = requests.post('https://events.pagerduty.com/v2/enqueue', 27 | data=json.dumps(payload), 28 | headers=header) 29 | 30 | if response.json()["status"] == "success": 31 | print('Incident created with with dedup key (also known as incident / alert key) of ' + '"' + response.json()['dedup_key'] + '"') 32 | else: 33 | print(response.text) # print error message if not successful 34 | 35 | if __name__ == '__main__': 36 | trigger_incident() 37 | -------------------------------------------------------------------------------- /REST_API_v2/Abilities/list_abilities.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | 34 | def list_abilities(): 35 | url = 'https://api.pagerduty.com/abilities' 36 | headers = { 37 | 'Accept': 'application/vnd.pagerduty+json;version=2', 38 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 39 | } 40 | r = requests.get(url, headers=headers) 41 | print('Status Code: {code}'.format(code=r.status_code)) 42 | print(r.json()) 43 | 44 | if __name__ == '__main__': 45 | list_abilities() 46 | -------------------------------------------------------------------------------- /REST_API_v2/Abilities/test_ability.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your ability ID 34 | ID = 'sso' 35 | 36 | 37 | def test_ability(): 38 | url = 'https://api.pagerduty.com/abilities/{id}'.format(id=ID) 39 | headers = { 40 | 'Accept': 'application/vnd.pagerduty+json;version=2', 41 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 42 | } 43 | r = requests.get(url, headers=headers) 44 | print('Status Code: {code}'.format(code=r.status_code)) 45 | print(r.text) 46 | 47 | if __name__ == '__main__': 48 | test_ability() 49 | -------------------------------------------------------------------------------- /REST_API_v2/AddOns/delete_addon.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match ID of resource you want to delete 34 | ID = 'PNIESDP' 35 | 36 | 37 | def delete_addon(): 38 | url = 'https://api.pagerduty.com/addons/{id}'.format(id=ID) 39 | headers = { 40 | 'Accept': 'application/vnd.pagerduty+json;version=2', 41 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 42 | } 43 | r = requests.delete(url, headers=headers) 44 | print('Status Code: {code}'.format(code=r.status_code)) 45 | print(r.text) 46 | 47 | if __name__ == '__main__': 48 | delete_addon() 49 | -------------------------------------------------------------------------------- /REST_API_v2/AddOns/get_addon.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match ID of resource you want to GET 34 | ID = 'PNIESDP' 35 | 36 | 37 | def get_addon(): 38 | url = 'https://api.pagerduty.com/addons/{id}'.format(id=ID) 39 | headers = { 40 | 'Accept': 'application/vnd.pagerduty+json;version=2', 41 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 42 | } 43 | r = requests.get(url, headers=headers) 44 | print('Status Code: {code}'.format(code=r.status_code)) 45 | print(r.json()) 46 | 47 | if __name__ == '__main__': 48 | get_addon() 49 | -------------------------------------------------------------------------------- /REST_API_v2/AddOns/install_addon.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match your chosen parameters 35 | SUMMARY = 'Insert addon summary here' 36 | NAME = 'Insert addon name here' 37 | SRC = 'https://intranet.example.com/status' 38 | SERVICES = [] 39 | 40 | 41 | def install_addon(): 42 | url = 'https://api.pagerduty.com/addons' 43 | headers = { 44 | 'Accept': 'application/vnd.pagerduty+json;version=2', 45 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 46 | 'Content-type': 'application/json' 47 | } 48 | payload = { 49 | 'addon': { 50 | 'summary': SUMMARY, 51 | 'name': NAME, 52 | 'src': SRC, 53 | 'services': SERVICES 54 | } 55 | } 56 | r = requests.post(url, headers=headers, data=json.dumps(payload)) 57 | print('Status Code: {code}'.format(code=r.status_code)) 58 | print(r.json()) 59 | 60 | if __name__ == '__main__': 61 | install_addon() 62 | -------------------------------------------------------------------------------- /REST_API_v2/AddOns/list_installed_addons.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your chosen parameters 34 | INCLUDE = [] 35 | SERVICE_IDS = [] 36 | FILTER = '' 37 | 38 | 39 | def list_installed_addons(): 40 | url = 'https://api.pagerduty.com/addons' 41 | headers = { 42 | 'Accept': 'application/vnd.pagerduty+json;version=2', 43 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 44 | } 45 | payload = { 46 | 'include[]': INCLUDE, 47 | 'service_ids[]': SERVICE_IDS, 48 | 'filter': FILTER 49 | } 50 | r = requests.get(url, headers=headers, params=payload) 51 | print('Status Code: {code}'.format(code=r.status_code)) 52 | print(r.json()) 53 | 54 | if __name__ == '__main__': 55 | list_installed_addons() 56 | -------------------------------------------------------------------------------- /REST_API_v2/AddOns/update_addon.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match ID of resource you want to update 35 | ID = 'P00HQZ9' 36 | 37 | # Update to match your chosen parameters 38 | SUMMARY = 'Insert updated addon summary here' 39 | NAME = 'Insert updated addon name here' 40 | SRC = 'https://intranet.example.com/updated_status_page' 41 | SERVICES = [] 42 | 43 | 44 | def update_addon(): 45 | url = 'https://api.pagerduty.com/addons/{id}'.format(id=ID) 46 | headers = { 47 | 'Accept': 'application/vnd.pagerduty+json;version=2', 48 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 49 | 'Content-type': 'application/json' 50 | } 51 | payload = { 52 | 'addon': { 53 | 'summary': SUMMARY, 54 | 'name': NAME, 55 | 'src': SRC, 56 | 'services': SERVICES 57 | } 58 | } 59 | r = requests.put(url, headers=headers, data=json.dumps(payload)) 60 | print('Status Code: ' + str(r.status_code)) 61 | print(r.json()) 62 | 63 | if __name__ == '__main__': 64 | update_addon() 65 | -------------------------------------------------------------------------------- /REST_API_v2/EscalationPolicies/create_escalation_policy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match your chosen parameters 35 | TYPE = 'escalation_policy' 36 | NAME = 'Insert resource name here' 37 | SUMMARY = 'Insert resource description here' 38 | REPEAT_ENABLED = True 39 | NUM_LOOPS = 3 40 | ESCALATION_RULES = [{ 41 | 'escalation_delay_in_minutes': 30, 42 | 'targets': [{ 43 | 'type': 'schedule', 44 | 'id': 'PTC959G' 45 | }] 46 | }] 47 | SERVICES = [] 48 | 49 | 50 | def create_escalation_policy(): 51 | url = 'https://api.pagerduty.com/escalation_policies' 52 | headers = { 53 | 'Accept': 'application/vnd.pagerduty+json;version=2', 54 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 55 | 'Content-type': 'application/json' 56 | } 57 | payload = { 58 | 'escalation_policy': { 59 | 'name': NAME, 60 | 'type': TYPE, 61 | 'summary': SUMMARY, 62 | 'repeat_enabled': REPEAT_ENABLED, 63 | 'num_loops': NUM_LOOPS, 64 | 'escalation_rules': ESCALATION_RULES, 65 | 'services': SERVICES 66 | } 67 | } 68 | r = requests.post(url, headers=headers, data=json.dumps(payload)) 69 | print('Status Code: {code}'.format(code=r.status_code)) 70 | print(r.json()) 71 | 72 | if __name__ == '__main__': 73 | create_escalation_policy() 74 | -------------------------------------------------------------------------------- /REST_API_v2/EscalationPolicies/delete_escalation_policy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match ID of resource you want to delete 34 | ID = 'P2ITA2T' 35 | 36 | 37 | def delete_escalation_policy(): 38 | url = 'https://api.pagerduty.com/escalation_policies/{id}'.format(id=ID) 39 | headers = { 40 | 'Accept': 'application/vnd.pagerduty+json;version=2', 41 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 42 | } 43 | r = requests.delete(url, headers=headers) 44 | print('Status Code: {code}'.format(code=r.status_code)) 45 | print(r.text) 46 | 47 | if __name__ == '__main__': 48 | delete_escalation_policy() 49 | -------------------------------------------------------------------------------- /REST_API_v2/EscalationPolicies/get_escalation_policy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match ID of resource you want to GET 34 | ID = 'PIX2DN3' 35 | 36 | # Update to match your chosen parameters 37 | INCLUDE = [] 38 | 39 | 40 | def get_escalation_policy(): 41 | url = 'https://api.pagerduty.com/escalation_policies/{id}'.format(id=ID) 42 | headers = { 43 | 'Accept': 'application/vnd.pagerduty+json;version=2', 44 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 45 | } 46 | payload = { 47 | 'include[]': INCLUDE 48 | } 49 | r = requests.get(url, headers=headers, params=payload) 50 | print('Status Code: {code}'.format(code=r.status_code)) 51 | print(r.json()) 52 | 53 | if __name__ == '__main__': 54 | get_escalation_policy() 55 | -------------------------------------------------------------------------------- /REST_API_v2/EscalationPolicies/list_escalation_policies.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your chosen parameters 34 | QUERY = '' 35 | USER_IDS = [] 36 | TEAM_IDS = [] 37 | INCLUDE = [] 38 | SORT_BY = 'name' 39 | 40 | 41 | def list_escalation_policies(): 42 | url = 'https://api.pagerduty.com/escalation_policies' 43 | headers = { 44 | 'Accept': 'application/vnd.pagerduty+json;version=2', 45 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 46 | } 47 | payload = { 48 | 'query': QUERY, 49 | 'user_ids[]': USER_IDS, 50 | 'team_ids[]': TEAM_IDS, 51 | 'include[]': INCLUDE, 52 | 'sort_by': SORT_BY 53 | } 54 | r = requests.get(url, headers=headers, params=payload) 55 | print('Status Code: {code}'.format(code=r.status_code)) 56 | print(r.json()) 57 | 58 | if __name__ == '__main__': 59 | list_escalation_policies() 60 | -------------------------------------------------------------------------------- /REST_API_v2/EscalationPolicies/update_escalation_policy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match ID of resource you want to update 35 | ID = 'PVHNG0S' 36 | 37 | # Update to match your chosen parameters 38 | TYPE = 'escalation_policy' 39 | NAME = 'Insert resource name here' 40 | SUMMARY = 'Insert resource description here' 41 | REPEAT_ENABLED = True 42 | NUM_LOOPS = 3 43 | ESCALATION_RULES = [ 44 | { 45 | 'escalation_delay_in_minutes': 30, 46 | 'targets': [ 47 | { 48 | 'type': 'schedule', 49 | 'id': 'PTC959G' 50 | } 51 | ] 52 | } 53 | ] 54 | SERVICES = [] 55 | 56 | 57 | def update_escalation_policy(): 58 | url = 'https://api.pagerduty.com/escalation_policies/{id}'.format(id=ID) 59 | headers = { 60 | 'Accept': 'application/vnd.pagerduty+json;version=2', 61 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 62 | 'Content-type': 'application/json' 63 | } 64 | payload = { 65 | 'escalation_policy': { 66 | 'name': NAME, 67 | 'type': TYPE, 68 | 'summary': SUMMARY, 69 | 'repeat_enabled': REPEAT_ENABLED, 70 | 'num_loops': NUM_LOOPS, 71 | 'escalation_rules': ESCALATION_RULES, 72 | 'services': SERVICES 73 | } 74 | } 75 | r = requests.put(url, headers=headers, data=json.dumps(payload)) 76 | print('Status Code: {code}'.format(code=r.status_code)) 77 | print(r.json()) 78 | 79 | if __name__ == '__main__': 80 | update_escalation_policy() 81 | -------------------------------------------------------------------------------- /REST_API_v2/Incidents/create_incident_note.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match your email address 35 | EMAIL = 'lucas@pagerduty.com' 36 | 37 | # Update to match your chosen parameters 38 | INCIDENT_ID = 'PI8BBP5' 39 | CONTENT = 'Enter your note content here' 40 | 41 | 42 | def create_incident_note(): 43 | url = 'https://api.pagerduty.com/incidents/{id}/notes'.format( 44 | id=INCIDENT_ID 45 | ) 46 | headers = { 47 | 'Accept': 'application/vnd.pagerduty+json;version=2', 48 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 49 | 'Content-type': 'application/json', 50 | 'From': EMAIL 51 | } 52 | payload = { 53 | 'note': { 54 | 'content': CONTENT 55 | } 56 | } 57 | r = requests.post(url, headers=headers, data=json.dumps(payload)) 58 | print('Status Code: {code}'.format(code=r.status_code)) 59 | print(r.json()) 60 | 61 | if __name__ == '__main__': 62 | create_incident_note() 63 | -------------------------------------------------------------------------------- /REST_API_v2/Incidents/get_incident.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your incident ID 34 | ID = 'P1DIBFS' 35 | 36 | 37 | def get_incident(): 38 | url = 'https://api.pagerduty.com/incidents/{id}'.format(id=ID) 39 | headers = { 40 | 'Accept': 'application/vnd.pagerduty+json;version=2', 41 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 42 | } 43 | r = requests.get(url, headers=headers) 44 | print('Status Code: {code}'.format(code=r.status_code)) 45 | print(r.json()) 46 | 47 | if __name__ == '__main__': 48 | get_incident() 49 | -------------------------------------------------------------------------------- /REST_API_v2/Incidents/list_incident_log_entries.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your chosen parameters 34 | INCIDENT_ID = 'P1DIBFS' 35 | TIME_ZONE = 'UTC' 36 | IS_OVERVIEW = False 37 | INCLUDE = [] 38 | 39 | 40 | def get_incident(): 41 | url = 'https://api.pagerduty.com/incidents/{id}/log_entries'.format( 42 | id=INCIDENT_ID 43 | ) 44 | headers = { 45 | 'Accept': 'application/vnd.pagerduty+json;version=2', 46 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 47 | } 48 | payload = { 49 | 'time_zone': TIME_ZONE, 50 | 'is_overview': IS_OVERVIEW, 51 | 'include[]': INCLUDE 52 | } 53 | r = requests.get(url, headers=headers, params=payload) 54 | print('Status Code: {code}'.format(code=r.status_code)) 55 | print(r.json()) 56 | 57 | if __name__ == '__main__': 58 | get_incident() 59 | -------------------------------------------------------------------------------- /REST_API_v2/Incidents/list_incident_notes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your incident ID 34 | INCIDENT_ID = 'P1DIBFS' 35 | 36 | 37 | def get_incident(): 38 | url = 'https://api.pagerduty.com/incidents/{id}/notes'.format( 39 | id=INCIDENT_ID 40 | ) 41 | headers = { 42 | 'Accept': 'application/vnd.pagerduty+json;version=2', 43 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 44 | } 45 | r = requests.get(url, headers=headers) 46 | print('Status Code: {code}'.format(code=r.status_code)) 47 | print(r.json()) 48 | 49 | if __name__ == '__main__': 50 | get_incident() 51 | -------------------------------------------------------------------------------- /REST_API_v2/Incidents/list_incidents.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your chosen parameters 34 | SINCE = '' 35 | UNTIL = '' 36 | DATE_RANGE = '' 37 | STATUSES = [] 38 | INCIDENT_KEY = '' 39 | SERVICE_IDS = [] 40 | TEAM_IDS = [] 41 | USER_IDS = [] 42 | URGENCIES = [] 43 | TIME_ZONE = 'UTC' 44 | SORT_BY = '' # comma-delineated list; see https://v2.developer.pagerduty.com/docs/sorting 45 | INCLUDE = [] 46 | 47 | 48 | def list_incidents(): 49 | url = 'https://api.pagerduty.com/incidents' 50 | headers = { 51 | 'Accept': 'application/vnd.pagerduty+json;version=2', 52 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 53 | } 54 | payload = { 55 | 'since': SINCE, 56 | 'until': UNTIL, 57 | 'date_range': DATE_RANGE, 58 | 'statuses[]': STATUSES, 59 | 'incident_key': INCIDENT_KEY, 60 | 'service_ids[]': SERVICE_IDS, 61 | 'team_ids[]': TEAM_IDS, 62 | 'user_ids[]': USER_IDS, 63 | 'urgencies[]': URGENCIES, 64 | 'time_zone': TIME_ZONE, 65 | 'sort_by': SORT_BY, 66 | 'include[]': INCLUDE 67 | } 68 | r = requests.get(url, headers=headers, params=payload) 69 | print('Status Code: {code}'.format(code=r.status_code)) 70 | print(r.json()) 71 | 72 | if __name__ == '__main__': 73 | list_incidents() 74 | -------------------------------------------------------------------------------- /REST_API_v2/Incidents/manage_incidents.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match your email address 35 | EMAIL = 'lucas@pagerduty.com' 36 | 37 | # Update to match your chosen parameters for each incident 38 | INCIDENT_ONE_ID = 'P1DIBFS' 39 | INCIDENT_ONE_STATUS = 'resolved' 40 | INCIDENT_ONE_ASSIGNEE_ID = '' 41 | INCIDENT_ONE_ASSIGNEE_TYPE = '' 42 | 43 | INCIDENT_TWO_ID = 'PKSPVAW' 44 | INCIDENT_TWO_STATUS = 'resolved' 45 | INCIDENT_TWO_ASSIGNEE_ID = '' 46 | INCIDENT_TWO_ASSIGNEE_TYPE = '' 47 | 48 | 49 | def manage_incidents(): 50 | url = 'https://api.pagerduty.com/incidents' 51 | headers = { 52 | 'Accept': 'application/vnd.pagerduty+json;version=2', 53 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 54 | 'Content-type': 'application/json', 55 | 'From': EMAIL 56 | } 57 | payload = { 58 | 'incidents': [ 59 | { 60 | 'id': INCIDENT_ONE_ID, 61 | 'type': 'incident', 62 | 'status': INCIDENT_ONE_STATUS, 63 | 'assigments': [{ 64 | 'assignee': { 65 | 'id': INCIDENT_ONE_ASSIGNEE_ID, 66 | 'type': INCIDENT_ONE_ASSIGNEE_TYPE 67 | } 68 | }] 69 | }, 70 | { 71 | 'id': INCIDENT_TWO_ID, 72 | 'type': 'incident', 73 | 'status': INCIDENT_TWO_STATUS, 74 | 'assignments': [{ 75 | 'assignee': { 76 | 'id': INCIDENT_TWO_ASSIGNEE_ID, 77 | 'type': INCIDENT_TWO_ASSIGNEE_TYPE 78 | } 79 | }] 80 | } 81 | ] 82 | } 83 | r = requests.put(url, headers=headers, data=json.dumps(payload)) 84 | print('Status Code: {code}'.format(code=r.status_code)) 85 | print(r.json()) 86 | 87 | if __name__ == '__main__': 88 | manage_incidents() 89 | -------------------------------------------------------------------------------- /REST_API_v2/Incidents/snooze_incident.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match your email address 35 | EMAIL = 'lucas@pagerduty.com' 36 | 37 | # Update to match your chosen parameters 38 | INCIDENT_ID = 'P7SP1VE' 39 | CONTENT = 'Enter your note content here' 40 | 41 | 42 | def snooze_incident(): 43 | url = 'https://api.pagerduty.com/incidents/{id}/snooze'.format( 44 | id=INCIDENT_ID 45 | ) 46 | headers = { 47 | 'Accept': 'application/vnd.pagerduty+json;version=2', 48 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 49 | 'Content-type': 'application/json', 50 | 'From': EMAIL 51 | } 52 | payload = { 53 | 'content': CONTENT, 54 | 'duration': 60 * 60 * 24 # 24 hours 55 | } 56 | r = requests.post(url, headers=headers, data=json.dumps(payload)) 57 | print('Status Code: {code}'.format(code=r.status_code)) 58 | print(r.json()) 59 | 60 | if __name__ == '__main__': 61 | snooze_incident() 62 | -------------------------------------------------------------------------------- /REST_API_v2/Incidents/trigger_incident.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '' 33 | SERVICE_ID = '' 34 | FROM = '' 35 | 36 | def trigger_incident(): 37 | """Triggers an incident via the V2 REST API using sample data.""" 38 | 39 | url = 'https://api.pagerduty.com/incidents' 40 | headers = { 41 | 'Content-Type': 'application/json', 42 | 'Accept': 'application/vnd.pagerduty+json;version=2', 43 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 44 | 'From': FROM 45 | } 46 | 47 | payload = { 48 | "incident": { 49 | "type": "incident", 50 | "title": "The server is on fire.", 51 | "service": { 52 | "id": SERVICE_ID, 53 | "type": "service_reference" 54 | }, 55 | "incident_key": "baf7cf21b1da41b4b0221008339ff3571", 56 | "body": { 57 | "type": "incident_body", 58 | "details": "A disk is getting full on this machine. You should investigate what is causing the disk to fill, and ensure that there is an automated process in place for ensuring data is rotated (eg. logs should have logrotate around them). If data is expected to stay on this disk forever, you should start planning to scale up to a larger disk." 59 | } 60 | } 61 | } 62 | 63 | r = requests.post(url, headers=headers, data=json.dumps(payload)) 64 | 65 | print('Status Code: {code}'.format(code=r.status_code)) 66 | print(r.json()) 67 | 68 | if __name__ == '__main__': 69 | trigger_incident() 70 | -------------------------------------------------------------------------------- /REST_API_v2/Incidents/update_incident.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match your email address 35 | EMAIL = 'lucas@pagerduty.com' 36 | 37 | # Update to match your chosen parameters for the incident 38 | INCIDENT_ID = 'PQQVDM1' 39 | TYPE = 'incident' 40 | SUMMARY = 'Enter your incident summary here' 41 | STATUS = 'resolved' 42 | ESCALATION_LEVEL = 1 43 | ASSIGNED_TO_USER = '' 44 | ESCALATION_POLICY = '' 45 | 46 | 47 | def update_incident(): 48 | url = 'https://api.pagerduty.com/incidents/{id}'.format(id=INCIDENT_ID) 49 | headers = { 50 | 'Accept': 'application/vnd.pagerduty+json;version=2', 51 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 52 | 'Content-type': 'application/json', 53 | 'From': EMAIL 54 | } 55 | payload = { 56 | 'incident': { 57 | 'type': TYPE, 58 | 'summary': SUMMARY, 59 | 'status': STATUS, 60 | 'escalation_level': ESCALATION_LEVEL, 61 | 'assigned_to_user': ASSIGNED_TO_USER, 62 | 'escalation_policy': ESCALATION_POLICY 63 | } 64 | } 65 | r = requests.put(url, headers=headers, data=json.dumps(payload)) 66 | print('Status Code: {code}'.format(code=r.status_code)) 67 | print(r.json()) 68 | 69 | if __name__ == '__main__': 70 | update_incident() 71 | -------------------------------------------------------------------------------- /REST_API_v2/LogEntries/get_log_entry.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match ID of resource you want to GET 34 | ID = 'Q1LLSJN8TZGO3Q' 35 | 36 | # Update to match your chosen parameters 37 | INCLUDE = [] 38 | 39 | 40 | def get_log_entry(): 41 | url = 'https://api.pagerduty.com/log_entries/{id}'.format(id=ID) 42 | headers = { 43 | 'Accept': 'application/vnd.pagerduty+json;version=2', 44 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 45 | } 46 | payload = { 47 | 'include[]': INCLUDE 48 | } 49 | r = requests.get(url, headers=headers, params=payload) 50 | print('Status Code: {code}'.format(code=r.status_code)) 51 | print(r.json()) 52 | 53 | if __name__ == '__main__': 54 | get_log_entry() 55 | -------------------------------------------------------------------------------- /REST_API_v2/LogEntries/list_log_entries.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your chosen parameters 34 | TIME_ZONE = 'UTC' 35 | SINCE = '' 36 | UNTIL = '' 37 | IS_OVERVIEW = False 38 | INCLUDE = [] 39 | 40 | 41 | def list_log_entries(): 42 | url = 'https://api.pagerduty.com/log_entries' 43 | headers = { 44 | 'Accept': 'application/vnd.pagerduty+json;version=2', 45 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 46 | } 47 | payload = { 48 | 'time_zone': TIME_ZONE, 49 | 'is_overview': IS_OVERVIEW, 50 | 'include[]': INCLUDE 51 | } 52 | if SINCE != '': 53 | payload['since'] = SINCE 54 | if UNTIL != '': 55 | payload['until'] = UNTIL 56 | r = requests.get(url, headers=headers, params=payload) 57 | print('Status Code: {code}'.format(code=r.status_code)) 58 | print(r.json()) 59 | 60 | if __name__ == '__main__': 61 | list_log_entries() 62 | -------------------------------------------------------------------------------- /REST_API_v2/MaintenanceWindows/create_maintenance_window.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match your email address 35 | EMAIL = 'lucas@pagerduty.com' 36 | 37 | # Update to match your chosen parameters 38 | START_TIME = '2016-05-23T14:00:00-07:00' 39 | END_TIME = '2016-05-23T18:00:00-07:00' 40 | DESCRIPTION = 'Enter your maintenance window description here' 41 | SERVICES = [{ 42 | 'id': 'PKWA90D', 43 | 'type': 'service_reference' 44 | }] 45 | TEAMS = [] 46 | TYPE = 'maintenance_window' 47 | 48 | 49 | def create_maintenance_window(): 50 | url = 'https://api.pagerduty.com/maintenance_windows' 51 | headers = { 52 | 'Accept': 'application/vnd.pagerduty+json;version=2', 53 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 54 | 'Content-type': 'application/json', 55 | 'From': EMAIL 56 | } 57 | payload = { 58 | 'maintenance_window': { 59 | 'start_time': START_TIME, 60 | 'end_time': END_TIME, 61 | 'description': DESCRIPTION, 62 | 'services': SERVICES, 63 | 'teams': TEAMS, 64 | 'type': TYPE 65 | } 66 | } 67 | r = requests.post(url, headers=headers, data=json.dumps(payload)) 68 | print('Status Code: {code}'.format(code=r.status_code)) 69 | print(r.json()) 70 | 71 | if __name__ == '__main__': 72 | create_maintenance_window() 73 | -------------------------------------------------------------------------------- /REST_API_v2/MaintenanceWindows/delete_or_end_maintenance_window.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match ID of resource you want to delete 34 | ID = 'PER23E0' 35 | 36 | 37 | def delete_maintenance_window(): 38 | url = 'https://api.pagerduty.com/maintenance_windows/{id}'.format(id=ID) 39 | headers = { 40 | 'Accept': 'application/vnd.pagerduty+json;version=2', 41 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 42 | } 43 | r = requests.delete(url, headers=headers) 44 | print('Status Code: {code}'.format(code=r.status_code)) 45 | print(r.text) 46 | 47 | if __name__ == '__main__': 48 | delete_maintenance_window() 49 | -------------------------------------------------------------------------------- /REST_API_v2/MaintenanceWindows/end_all_maintenance_windows.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2018, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | # -------------------------------------------------------------------------------- 29 | # INSTRUCTIONS 30 | # 31 | # This script will search for all currently active maintenance windows on all 32 | # services and end them. It does not support pagination, so it is limited to 100 33 | # maintenance windows (by default it will sort by name) 34 | # 35 | # REQUIRED: API_KEY, EMAIL 36 | # 37 | # OPTIONAL: You can set the END_TIME to a future date if required. 38 | # 39 | # # Date format: '2018-09-30T14:00:00' 40 | # 41 | # There are also other parameters for filtering maintenance windows. 42 | # 43 | # -------------------------------------------------------------------------------- 44 | 45 | import requests 46 | import datetime 47 | 48 | current_time = datetime.datetime.now() 49 | 50 | # Update to match your v2 REST API key 51 | API_KEY = '' 52 | 53 | # Update to match your login email 54 | EMAIL = '' 55 | 56 | # Update to match your chosen parameters 57 | # You can also specify a different end date here instead (Date format: '2018-09-30T14:00:00') 58 | END_TIME = current_time 59 | TEAM_IDS = [] 60 | SERVICE_IDS = [] 61 | INCLUDE = [] 62 | FILTER = 'ongoing' 63 | QUERY = '' 64 | 65 | 66 | def get_maintenance_windows(): 67 | url = 'https://api.pagerduty.com/maintenance_windows?total=true' 68 | headers = { 69 | 'Accept': 'application/vnd.pagerduty+json;version=2', 70 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 71 | } 72 | payload = { 73 | 'team_ids[]': TEAM_IDS, 74 | 'service_ids[]': SERVICE_IDS, 75 | 'include[]': INCLUDE, 76 | 'filter': FILTER, 77 | 'query': QUERY 78 | } 79 | maintenance_windows_ids = [] 80 | r = requests.get(url, headers=headers, params=payload) 81 | print('Getting ongoing maintenance windows...') 82 | print('\tStatus Code: {code}'.format(code=r.status_code)) 83 | if r.status_code < 200 or r.status_code >= 204: 84 | print("\tThere was an error getting your maintenance windows.") 85 | print("\tPlease ensure that the login email and v2 REST API key in this script are correct.") 86 | print(r.text) 87 | return maintenance_windows_ids 88 | maintenance_list = r.json() 89 | ids = maintenance_list['maintenance_windows'] 90 | total = int(maintenance_list['total']) 91 | 92 | if total > 0: 93 | if total == 1: 94 | print("\t1 ongoing maintenance window found:") 95 | if total == 2: 96 | print("\t", total, 'ongoing maintenance windows found') 97 | for maintenance_window in range(total): 98 | maintenance_windows_ids.append(ids[maintenance_window]['id']) 99 | print("\t", maintenance_windows_ids) 100 | else: 101 | print("No ongoing maintenance windows found") 102 | return maintenance_windows_ids 103 | 104 | 105 | def end_maintenance_window(MAINTENANCE_WINDOWS): 106 | if len(MAINTENANCE_WINDOWS) == 1: 107 | print("Ending maintenance window...") 108 | else: 109 | print("Ending maintenance windows...") 110 | headers = { 111 | 'Accept': 'application/vnd.pagerduty+json;version=2', 112 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 113 | } 114 | for maintenance_window in range(len(MAINTENANCE_WINDOWS)): 115 | url = 'https://api.pagerduty.com/maintenance_windows/{id}'.format(id=MAINTENANCE_WINDOWS[maintenance_window]) 116 | print("\t", str(MAINTENANCE_WINDOWS[maintenance_window])) 117 | r = requests.delete(url, headers=headers) 118 | print('\tStatus Code: {code}'.format(code=r.status_code)) 119 | if r.status_code == 204: 120 | print('\tMaintenance window ended successfully!') 121 | else: 122 | print("\tThere was an error ending this maintenance window") 123 | print("\tPlease ensure that the login email and v2 REST API key in this script have proper permissions") 124 | return maintenance_windows_ids 125 | print(r.text) 126 | 127 | if __name__ == '__main__': 128 | 129 | if EMAIL == '': 130 | print("Please add your login email to this script and run it again.") 131 | elif API_KEY == '': 132 | print("Please add your v2 REST API key to this script and run it again.") 133 | else: 134 | MAINTENANCE_WINDOWS = get_maintenance_windows() 135 | if MAINTENANCE_WINDOWS != []: 136 | end_maintenance_window(MAINTENANCE_WINDOWS) 137 | 138 | 139 | # ----------------------------------------------------------------------- 140 | 141 | -------------------------------------------------------------------------------- /REST_API_v2/MaintenanceWindows/get_maintenance_window.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match ID of resource you want to GET 34 | ID = 'P5B7MVH' 35 | 36 | # Update to match your chosen parameters 37 | INCLUDE = [] 38 | 39 | 40 | def get_maintenance_window(): 41 | url = 'https://api.pagerduty.com/maintenance_windows/{id}'.format(id=ID) 42 | headers = { 43 | 'Accept': 'application/vnd.pagerduty+json;version=2', 44 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 45 | } 46 | payload = { 47 | 'include[]': INCLUDE 48 | } 49 | r = requests.get(url, headers=headers, params=payload) 50 | print('Status Code: {code}'.format(code=r.status_code)) 51 | print(r.json()) 52 | 53 | if __name__ == '__main__': 54 | get_maintenance_window() 55 | -------------------------------------------------------------------------------- /REST_API_v2/MaintenanceWindows/list_maintenance_windows.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your chosen parameters 34 | TEAM_IDS = [] 35 | SERVICE_IDS = [] 36 | INCLUDE = [] 37 | FILTER = 'all' 38 | QUERY = '' 39 | 40 | 41 | def list_maintenance_windows(): 42 | url = 'https://api.pagerduty.com/maintenance_windows' 43 | headers = { 44 | 'Accept': 'application/vnd.pagerduty+json;version=2', 45 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 46 | } 47 | payload = { 48 | 'team_ids[]': TEAM_IDS, 49 | 'service_ids[]': SERVICE_IDS, 50 | 'include[]': INCLUDE, 51 | 'filter': FILTER, 52 | 'query': QUERY 53 | } 54 | r = requests.get(url, headers=headers, params=payload) 55 | print('Status Code: {code}'.format(code=r.status_code)) 56 | print(r.json()) 57 | 58 | if __name__ == '__main__': 59 | list_maintenance_windows() 60 | -------------------------------------------------------------------------------- /REST_API_v2/MaintenanceWindows/update_maintenance_window.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match ID of resource you want to update 35 | ID = 'PE54NW4' 36 | 37 | # Update to match your chosen parameters 38 | START_TIME = '2016-05-23T14:00:00-07:00' 39 | END_TIME = '2016-05-23T18:00:00-07:00' 40 | DESCRIPTION = 'Enter your updated maintenance window description here' 41 | SERVICES = [{ 42 | 'id': 'PKWA90D', 43 | 'type': 'service_reference' 44 | }] 45 | TEAMS = [] 46 | TYPE = 'maintenance_window' 47 | 48 | 49 | def update_maintenance_window(): 50 | url = 'https://api.pagerduty.com/maintenance_windows/{id}'.format(id=ID) 51 | headers = { 52 | 'Accept': 'application/vnd.pagerduty+json;version=2', 53 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 54 | 'Content-type': 'application/json' 55 | } 56 | payload = { 57 | 'maintenance_window': { 58 | 'start_time': START_TIME, 59 | 'end_time': END_TIME, 60 | 'description': DESCRIPTION, 61 | 'services': SERVICES, 62 | 'teams': TEAMS, 63 | 'type': TYPE 64 | } 65 | } 66 | r = requests.put(url, headers=headers, data=json.dumps(payload)) 67 | print('Status Code: {code}'.format(code=r.status_code)) 68 | print(r.json()) 69 | 70 | if __name__ == '__main__': 71 | update_maintenance_window() 72 | -------------------------------------------------------------------------------- /REST_API_v2/Notifications/list_notifications.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your chosen parameters 34 | TIME_ZONE = 'UTC' 35 | SINCE = '2016-05-15' 36 | UNTIL = '2016-05-20' 37 | FILTER = 'sms_notification' 38 | INCLUDE = [] 39 | 40 | 41 | def list_notifications(): 42 | url = 'https://api.pagerduty.com/notifications' 43 | headers = { 44 | 'Accept': 'application/vnd.pagerduty+json;version=2', 45 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 46 | } 47 | payload = { 48 | 'time_zone': TIME_ZONE, 49 | 'since': SINCE, 50 | 'until': UNTIL, 51 | 'filter': FILTER, 52 | 'include[]': INCLUDE 53 | } 54 | r = requests.get(url, headers=headers, params=payload) 55 | print('Status Code: {code}'.format(code=r.status_code)) 56 | print(r.json()) 57 | 58 | if __name__ == '__main__': 59 | list_notifications() 60 | -------------------------------------------------------------------------------- /REST_API_v2/OnCalls/list_oncalls.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your chosen parameters 34 | TIME_ZONE = 'UTC' 35 | INCLUDE = [] 36 | USER_IDS = [] 37 | ESCALATION_POLICY_IDS = [] 38 | SCHEDULE_IDS = [] 39 | SINCE = '' 40 | UNTIL = '' 41 | EARLIEST = False 42 | 43 | 44 | def list_oncalls(): 45 | url = 'https://api.pagerduty.com/oncalls' 46 | headers = { 47 | 'Accept': 'application/vnd.pagerduty+json;version=2', 48 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 49 | } 50 | payload = { 51 | 'time_zone': TIME_ZONE, 52 | 'include[]': INCLUDE, 53 | 'user_ids[]': USER_IDS, 54 | 'escalation_policy_ids[]': ESCALATION_POLICY_IDS, 55 | 'schedule_ids[]': SCHEDULE_IDS, 56 | 'since': SINCE, 57 | 'until': UNTIL, 58 | 'earliest': EARLIEST 59 | } 60 | r = requests.get(url, headers=headers, params=payload) 61 | print('Status Code: {code}'.format(code=r.status_code)) 62 | print(r.json()) 63 | 64 | if __name__ == '__main__': 65 | list_oncalls() 66 | -------------------------------------------------------------------------------- /REST_API_v2/Schedules/create_override.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match the schedule ID 35 | SCHEDULE_ID = 'PJGJ9RZ' 36 | 37 | # Update to match your chosen parameters 38 | USER_ID = 'PAZZ8LZ' 39 | START = '2016-06-01' 40 | END = '2016-07-01' 41 | 42 | 43 | def create_override(): 44 | url = 'https://api.pagerduty.com/schedules/{id}/overrides'.format( 45 | id=SCHEDULE_ID 46 | ) 47 | headers = { 48 | 'Accept': 'application/vnd.pagerduty+json;version=2', 49 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 50 | 'Content-type': 'application/json' 51 | } 52 | payload = { 53 | 'override': { 54 | 'start': START, 55 | 'end': END, 56 | 'user': { 57 | 'id': USER_ID, 58 | 'type': 'user_reference' 59 | } 60 | } 61 | } 62 | r = requests.post(url, headers=headers, data=json.dumps(payload)) 63 | print('Status Code: {code}'.format(code=r.status_code)) 64 | print(r.json()) 65 | 66 | if __name__ == '__main__': 67 | create_override() 68 | -------------------------------------------------------------------------------- /REST_API_v2/Schedules/create_schedule.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match your chosen parameters 35 | OVERFLOW = False 36 | 37 | # Update to match your chosen parameters for the overall schedule 38 | TYPE = 'schedule' 39 | SUMMARY = 'Insert your schedule summary here' 40 | NAME = 'Insert your schedule name here' 41 | TIME_ZONE = 'UTC' 42 | ESCALATION_POLICIES = [] 43 | TEAMS = [] 44 | 45 | # Update to match your chosen parameters for each schedule layer 46 | LAYER_ONE_START = '2016-05-23T18:00:00-07:00' 47 | LAYER_ONE_END = '2016-06-23T18:00:00-07:00' 48 | LAYER_ONE_USERS = [ 49 | { 50 | 'id': 'PAZZ8LZ', 51 | 'type': 'user_reference' 52 | }, 53 | { 54 | 'id': 'P1PJUIZ', 55 | 'type': 'user_reference' 56 | } 57 | ] 58 | LAYER_ONE_RESTRICTION_TYPE = 'Daily' 59 | LAYER_ONE_RESTRICTIONS = [] 60 | LAYER_ONE_ROTATION_VIRTUAL_START = '2016-05-23T18:00:00-07:00' 61 | LAYER_ONE_PRIORITY = 1 62 | LAYER_ONE_ROTATION_TURN_LENGTH_SECONDS = 60 * 60 * 24 # 24 hours 63 | LAYER_ONE_NAME = 'Insert layer one name here' 64 | 65 | LAYER_TWO_START = '2016-05-23T18:00:00-07:00' 66 | LAYER_TWO_END = '2016-06-23T18:00:00-07:00' 67 | LAYER_TWO_USERS = [ 68 | { 69 | 'id': 'POC4AOM', 70 | 'type': 'user_reference' 71 | }, 72 | { 73 | 'id': 'PLUWO2C', 74 | 'type': 'user_reference' 75 | } 76 | ] 77 | LAYER_TWO_RESTRICTION_TYPE = 'Weekly' 78 | LAYER_TWO_RESTRICTIONS = [] 79 | LAYER_TWO_ROTATION_VIRTUAL_START = '2016-05-23T18:00:00-07:00' 80 | LAYER_TWO_PRIORITY = 1 81 | LAYER_TWO_ROTATION_TURN_LENGTH_SECONDS = 60 * 60 * 24 # 24 hours 82 | LAYER_TWO_NAME = 'Insert layer two name here' 83 | 84 | 85 | def create_schedule(): 86 | url = 'https://api.pagerduty.com/schedules' 87 | headers = { 88 | 'Accept': 'application/vnd.pagerduty+json;version=2', 89 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 90 | 'Content-type': 'application/json' 91 | } 92 | payload = { 93 | 'overflow': OVERFLOW, 94 | 'schedule': { 95 | 'type': TYPE, 96 | 'summary': SUMMARY, 97 | 'name': NAME, 98 | 'time_zone': TIME_ZONE, 99 | 'escalation_policies': ESCALATION_POLICIES, 100 | 'teams': TEAMS, 101 | 'schedule_layers': [ 102 | { 103 | 'start': LAYER_ONE_START, 104 | 'end': LAYER_ONE_END, 105 | 'users': LAYER_ONE_USERS, 106 | 'restriction_type': LAYER_ONE_RESTRICTION_TYPE, 107 | 'restrictions': LAYER_ONE_RESTRICTIONS, 108 | 'rotation_virtual_start': LAYER_ONE_ROTATION_VIRTUAL_START, 109 | 'priority': LAYER_ONE_PRIORITY, 110 | 'rotation_turn_length_seconds': 111 | LAYER_ONE_ROTATION_TURN_LENGTH_SECONDS, 112 | 'name': LAYER_ONE_NAME 113 | }, 114 | { 115 | 'start': LAYER_TWO_START, 116 | 'end': LAYER_TWO_END, 117 | 'users': LAYER_TWO_USERS, 118 | 'restriction_type': LAYER_TWO_RESTRICTION_TYPE, 119 | 'restrictions': LAYER_TWO_RESTRICTIONS, 120 | 'rotation_virtual_start': LAYER_TWO_ROTATION_VIRTUAL_START, 121 | 'priority': LAYER_TWO_PRIORITY, 122 | 'rotation_turn_length_seconds': 123 | LAYER_TWO_ROTATION_TURN_LENGTH_SECONDS, 124 | 'name': LAYER_TWO_NAME 125 | } 126 | ] 127 | } 128 | } 129 | r = requests.post(url, headers=headers, data=json.dumps(payload)) 130 | print('Status Code: {code}'.format(code=r.status_code)) 131 | print(r.json()) 132 | 133 | if __name__ == '__main__': 134 | create_schedule() 135 | -------------------------------------------------------------------------------- /REST_API_v2/Schedules/delete_override.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match the IDs of the schedule and override you want to delete 34 | SCHEDULE_ID = 'PJGJ9RZ' 35 | OVERRIDE_ID = 'Q0PVCKPSTNQUGG' 36 | 37 | 38 | def delete_override(): 39 | url = 'https://api.pagerduty.com/schedules/{sid}/overrides/{oid}'.format( 40 | sid=SCHEDULE_ID, 41 | oid=OVERRIDE_ID 42 | ) 43 | headers = { 44 | 'Accept': 'application/vnd.pagerduty+json;version=2', 45 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 46 | } 47 | r = requests.delete(url, headers=headers) 48 | print('Status Code: {code}'.format(code=r.status_code)) 49 | print(r.text) 50 | 51 | if __name__ == '__main__': 52 | delete_override() 53 | -------------------------------------------------------------------------------- /REST_API_v2/Schedules/delete_schedule.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match ID of resource you want to delete 34 | ID = 'PQX3A8C' 35 | 36 | 37 | def delete_schedule(): 38 | url = 'https://api.pagerduty.com/schedules/{id}'.format(id=ID) 39 | headers = { 40 | 'Accept': 'application/vnd.pagerduty+json;version=2', 41 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 42 | } 43 | r = requests.delete(url, headers=headers) 44 | print('Status Code: {code}'.format(code=r.status_code)) 45 | print(r.text) 46 | 47 | if __name__ == '__main__': 48 | delete_schedule() 49 | -------------------------------------------------------------------------------- /REST_API_v2/Schedules/get_schedule.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your schedule ID 34 | ID = 'PW73MZF' 35 | 36 | # Update to match your chosen parameters 37 | TIME_ZONE = 'UTC' 38 | SINCE = '' 39 | UNTIL = '' 40 | 41 | 42 | def get_schedule(): 43 | url = 'https://api.pagerduty.com/schedules/{id}'.format(id=ID) 44 | headers = { 45 | 'Accept': 'application/vnd.pagerduty+json;version=2', 46 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 47 | } 48 | payload = { 49 | 'time_zone': TIME_ZONE 50 | } 51 | if SINCE != '': 52 | payload['since'] = SINCE 53 | if UNTIL != '': 54 | payload['until'] = UNTIL 55 | r = requests.get(url, headers=headers, params=payload) 56 | print('Status Code: {code}'.format(code=r.status_code)) 57 | print(r.json()) 58 | 59 | if __name__ == '__main__': 60 | get_schedule() 61 | -------------------------------------------------------------------------------- /REST_API_v2/Schedules/list_oncall_users.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match the schedule ID 34 | SCHEDULE_ID = 'PJGJ9RZ' 35 | 36 | # Update to match your chosen parameters 37 | SINCE = '' 38 | UNTIL = '' 39 | 40 | 41 | def list_overrides(): 42 | url = 'https://api.pagerduty.com/schedules/{id}/users'.format( 43 | id=SCHEDULE_ID 44 | ) 45 | headers = { 46 | 'Accept': 'application/vnd.pagerduty+json;version=2', 47 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 48 | } 49 | payload = {} 50 | if SINCE != '': 51 | payload['since'] = SINCE 52 | if UNTIL != '': 53 | payload['until'] = UNTIL 54 | r = requests.get(url, headers=headers, params=payload) 55 | print('Status Code: {code}'.format(code=r.status_code)) 56 | print(r.json()) 57 | 58 | if __name__ == '__main__': 59 | list_overrides() 60 | -------------------------------------------------------------------------------- /REST_API_v2/Schedules/list_overrides.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match the schedule ID 34 | SCHEDULE_ID = 'PJGJ9RZ' 35 | 36 | # Update to match your chosen parameters 37 | SINCE = '2016-05-01' 38 | UNTIL = '2016-06-01' 39 | EDITABLE = False 40 | OVERFLOW = False 41 | 42 | 43 | def list_overrides(): 44 | url = 'https://api.pagerduty.com/schedules/{id}/overrides'.format( 45 | id=SCHEDULE_ID 46 | ) 47 | headers = { 48 | 'Accept': 'application/vnd.pagerduty+json;version=2', 49 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 50 | } 51 | payload = { 52 | 'since': SINCE, 53 | 'until': UNTIL, 54 | 'editable': EDITABLE, 55 | 'overflow': OVERFLOW 56 | } 57 | r = requests.get(url, headers=headers, params=payload) 58 | print('Status Code: {code}'.format(code=r.status_code)) 59 | print(r.json()) 60 | 61 | if __name__ == '__main__': 62 | list_overrides() 63 | -------------------------------------------------------------------------------- /REST_API_v2/Schedules/list_schedules.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your chosen parameters 34 | QUERY = '' 35 | 36 | 37 | def list_schedules(): 38 | url = 'https://api.pagerduty.com/schedules' 39 | headers = { 40 | 'Accept': 'application/vnd.pagerduty+json;version=2', 41 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 42 | } 43 | payload = { 44 | 'query': QUERY 45 | } 46 | r = requests.get(url, headers=headers, params=payload) 47 | print('Status Code: {code}'.format(code=r.status_code)) 48 | print(r.json()) 49 | 50 | if __name__ == '__main__': 51 | list_schedules() 52 | -------------------------------------------------------------------------------- /REST_API_v2/Schedules/preview_schedule.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match your chosen parameters 35 | OVERFLOW = False 36 | SINCE = '2016-05-25T00:00:00-07:00' 37 | UNTIL = '2016-06-01T00:00:00-07:00' 38 | 39 | # Update to match your chosen parameters for the overall schedule 40 | TYPE = 'schedule' 41 | SUMMARY = 'Insert your schedule summary here' 42 | NAME = 'Insert your schedule name here' 43 | TIME_ZONE = 'UTC' 44 | ESCALATION_POLICIES = [] 45 | TEAMS = [] 46 | 47 | # Update to match your chosen parameters for each schedule layer 48 | LAYER_ONE_START = '2016-05-23T18:00:00-07:00' 49 | LAYER_ONE_END = '2016-06-23T18:00:00-07:00' 50 | LAYER_ONE_USERS = [ 51 | { 52 | 'user': { 53 | 'id': 'PAZZ8LZ', 54 | 'type': 'user_reference' 55 | } 56 | }, 57 | { 58 | 'user': { 59 | 'id': 'P1PJUIZ', 60 | 'type': 'user_reference' 61 | } 62 | } 63 | ] 64 | LAYER_ONE_RESTRICTION_TYPE = 'Daily' 65 | LAYER_ONE_RESTRICTIONS = [] 66 | LAYER_ONE_ROTATION_VIRTUAL_START = '2016-05-23T18:00:00-07:00' 67 | LAYER_ONE_PRIORITY = 1 68 | LAYER_ONE_ROTATION_TURN_LENGTH_SECONDS = 60 * 60 * 24 # 24 hours 69 | LAYER_ONE_NAME = 'Insert layer one name here' 70 | 71 | LAYER_TWO_START = '2016-05-23T18:00:00-07:00' 72 | LAYER_TWO_END = '2016-06-23T18:00:00-07:00' 73 | LAYER_TWO_USERS = [ 74 | { 75 | 'user': { 76 | 'id': 'POC4AOM', 77 | 'type': 'user_reference' 78 | } 79 | }, 80 | { 81 | 'user': { 82 | 'id': 'PLUWO2C', 83 | 'type': 'user_reference' 84 | } 85 | } 86 | ] 87 | LAYER_TWO_RESTRICTION_TYPE = 'Weekly' 88 | LAYER_TWO_RESTRICTIONS = [] 89 | LAYER_TWO_ROTATION_VIRTUAL_START = '2016-05-23T18:00:00-07:00' 90 | LAYER_TWO_PRIORITY = 1 91 | LAYER_TWO_ROTATION_TURN_LENGTH_SECONDS = 60 * 60 * 24 # 24 hours 92 | LAYER_TWO_NAME = 'Insert layer two name here' 93 | 94 | 95 | def preview_schedule(): 96 | url = 'https://api.pagerduty.com/schedules/preview' 97 | headers = { 98 | 'Accept': 'application/vnd.pagerduty+json;version=2', 99 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 100 | 'Content-type': 'application/json' 101 | } 102 | payload = { 103 | 'since': SINCE, 104 | 'until': UNTIL, 105 | 'overflow': OVERFLOW, 106 | 'schedule': { 107 | 'type': TYPE, 108 | 'summary': SUMMARY, 109 | 'name': NAME, 110 | 'time_zone': TIME_ZONE, 111 | 'escalation_policies': ESCALATION_POLICIES, 112 | 'teams': TEAMS, 113 | 'schedule_layers': [ 114 | { 115 | 'start': LAYER_ONE_START, 116 | 'end': LAYER_ONE_END, 117 | 'users': LAYER_ONE_USERS, 118 | 'restriction_type': LAYER_ONE_RESTRICTION_TYPE, 119 | 'restrictions': LAYER_ONE_RESTRICTIONS, 120 | 'rotation_virtual_start': LAYER_ONE_ROTATION_VIRTUAL_START, 121 | 'priority': LAYER_ONE_PRIORITY, 122 | 'rotation_turn_length_seconds': 123 | LAYER_ONE_ROTATION_TURN_LENGTH_SECONDS, 124 | 'name': LAYER_ONE_NAME 125 | }, 126 | { 127 | 'start': LAYER_TWO_START, 128 | 'end': LAYER_TWO_END, 129 | 'users': LAYER_TWO_USERS, 130 | 'restriction_type': LAYER_TWO_RESTRICTION_TYPE, 131 | 'restrictions': LAYER_TWO_RESTRICTIONS, 132 | 'rotation_virtual_start': LAYER_TWO_ROTATION_VIRTUAL_START, 133 | 'priority': LAYER_TWO_PRIORITY, 134 | 'rotation_turn_length_seconds': 135 | LAYER_TWO_ROTATION_TURN_LENGTH_SECONDS, 136 | 'name': LAYER_TWO_NAME 137 | } 138 | ] 139 | } 140 | } 141 | r = requests.post(url, headers=headers, data=json.dumps(payload)) 142 | print('Status Code: {code}'.format(code=r.status_code)) 143 | print(r.json()) 144 | 145 | if __name__ == '__main__': 146 | preview_schedule() 147 | -------------------------------------------------------------------------------- /REST_API_v2/Schedules/update_schedule.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match ID of resource you want to update 35 | ID = 'PM6GOQG' 36 | 37 | # Update to match your chosen parameters 38 | OVERFLOW = False 39 | 40 | # Update to match your chosen parameters for the overall schedule 41 | TYPE = 'schedule' 42 | SUMMARY = 'Insert your schedule summary here' 43 | NAME = 'Insert your schedule name here' 44 | TIME_ZONE = 'UTC' 45 | ESCALATION_POLICIES = [] 46 | TEAMS = [] 47 | 48 | # Update to match your chosen parameters for each schedule layer 49 | LAYER_ONE_START = '2016-05-23T18:00:00-07:00' 50 | LAYER_ONE_END = '2016-06-23T18:00:00-07:00' 51 | LAYER_ONE_USERS = [ 52 | { 53 | 'user': { 54 | 'id': 'PIZFCCH', 55 | 'type': 'user_reference' 56 | } 57 | }, 58 | { 59 | 'user': { 60 | 'id': 'P1PJUIZ', 61 | 'type': 'user_reference' 62 | } 63 | } 64 | ] 65 | LAYER_ONE_RESTRICTION_TYPE = 'Daily' 66 | LAYER_ONE_RESTRICTIONS = [] 67 | LAYER_ONE_ROTATION_VIRTUAL_START = '2016-05-23T18:00:00-07:00' 68 | LAYER_ONE_PRIORITY = 1 69 | LAYER_ONE_ROTATION_TURN_LENGTH_SECONDS = 60 * 60 * 24 # 24 hours 70 | LAYER_ONE_NAME = 'Insert layer one name here' 71 | 72 | LAYER_TWO_START = '2016-05-23T18:00:00-07:00' 73 | LAYER_TWO_END = '2016-06-23T18:00:00-07:00' 74 | LAYER_TWO_USERS = [ 75 | { 76 | 'user': { 77 | 'id': 'POC4AOM', 78 | 'type': 'user_reference' 79 | } 80 | }, 81 | { 82 | 'user': { 83 | 'id': 'PLUWO2C', 84 | 'type': 'user_reference' 85 | } 86 | } 87 | ] 88 | LAYER_TWO_RESTRICTION_TYPE = 'Weekly' 89 | LAYER_TWO_RESTRICTIONS = [] 90 | LAYER_TWO_ROTATION_VIRTUAL_START = '2016-05-23T18:00:00-07:00' 91 | LAYER_TWO_PRIORITY = 1 92 | LAYER_TWO_ROTATION_TURN_LENGTH_SECONDS = 60 * 60 * 24 # 24 hours 93 | LAYER_TWO_NAME = 'Insert layer two name here' 94 | 95 | 96 | def update_schedule(): 97 | url = 'https://api.pagerduty.com/schedules/{id}'.format(id=ID) 98 | headers = { 99 | 'Accept': 'application/vnd.pagerduty+json;version=2', 100 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 101 | 'Content-type': 'application/json' 102 | } 103 | payload = { 104 | 'overflow': OVERFLOW, 105 | 'schedule': { 106 | 'type': TYPE, 107 | 'summary': SUMMARY, 108 | 'name': NAME, 109 | 'time_zone': TIME_ZONE, 110 | 'escalation_policies': ESCALATION_POLICIES, 111 | 'teams': TEAMS, 112 | 'schedule_layers': [ 113 | { 114 | 'start': LAYER_ONE_START, 115 | 'end': LAYER_ONE_END, 116 | 'users': LAYER_ONE_USERS, 117 | 'restriction_type': LAYER_ONE_RESTRICTION_TYPE, 118 | 'restrictions': LAYER_ONE_RESTRICTIONS, 119 | 'rotation_virtual_start': LAYER_ONE_ROTATION_VIRTUAL_START, 120 | 'priority': LAYER_ONE_PRIORITY, 121 | 'rotation_turn_length_seconds': 122 | LAYER_ONE_ROTATION_TURN_LENGTH_SECONDS, 123 | 'name': LAYER_ONE_NAME 124 | }, 125 | { 126 | 'start': LAYER_TWO_START, 127 | 'end': LAYER_TWO_END, 128 | 'users': LAYER_TWO_USERS, 129 | 'restriction_type': LAYER_TWO_RESTRICTION_TYPE, 130 | 'restrictions': LAYER_TWO_RESTRICTIONS, 131 | 'rotation_virtual_start': LAYER_TWO_ROTATION_VIRTUAL_START, 132 | 'priority': LAYER_TWO_PRIORITY, 133 | 'rotation_turn_length_seconds': 134 | LAYER_TWO_ROTATION_TURN_LENGTH_SECONDS, 135 | 'name': LAYER_TWO_NAME 136 | } 137 | ] 138 | } 139 | } 140 | r = requests.put(url, headers=headers, data=json.dumps(payload)) 141 | print('Status Code: {code}'.format(code=r.status_code)) 142 | print(r.json()) 143 | 144 | if __name__ == '__main__': 145 | update_schedule() 146 | -------------------------------------------------------------------------------- /REST_API_v2/Services/create_integration.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match the service ID 35 | SERVICE_ID = 'PK2X17C' 36 | 37 | # Update to match your chosen parameters 38 | TYPE = 'generic_email_inbound_integration' 39 | SUMMARY = 'Enter your integration summary here' 40 | NAME = 'Enter your integration name here' 41 | VENDOR = None 42 | # Only required if creating email integration 43 | INTEGRATION_EMAIL = 'insert_email@ENTER_YOUR_PD_SUBDOMAIN.pagerduty.com' 44 | 45 | 46 | def create_integration(): 47 | url = 'https://api.pagerduty.com/services/{id}/integrations'.format( 48 | id=SERVICE_ID 49 | ) 50 | headers = { 51 | 'Accept': 'application/vnd.pagerduty+json;version=2', 52 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 53 | 'Content-type': 'application/json' 54 | } 55 | payload = { 56 | 'integration': { 57 | 'type': TYPE, 58 | 'summary': SUMMARY, 59 | 'name': NAME, 60 | 'vendor': VENDOR 61 | } 62 | } 63 | if TYPE == 'generic_email_inbound_integration': 64 | payload['integration']['integration_email'] = INTEGRATION_EMAIL 65 | r = requests.post(url, headers=headers, data=json.dumps(payload)) 66 | print('Status Code: {code}'.format(code=r.status_code)) 67 | print(r.json()) 68 | 69 | if __name__ == '__main__': 70 | create_integration() 71 | -------------------------------------------------------------------------------- /REST_API_v2/Services/create_service.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match your chosen parameters 35 | NAME = 'Insert service name here' 36 | DESCRIPTION = 'Insert service description here' 37 | ESCALATION_POLICY_ID = 'PIX2DN3' 38 | TYPE = 'service' 39 | AUTO_RESOLVE_TIMEOUT = 14400 # 4 hours 40 | ACKNOWLEDGEMENT_TIMEOUT = 1800 # 30 minutes 41 | TEAMS = [] 42 | INCIDENT_URGENCY = 'high' # used during support hours or as default urgency 43 | OUTSIDE_SUPPORT_HOURS_URGENCY = 'low' 44 | SCHEDULED_ACTIONS = [] 45 | SUPPORT_HOURS = { 46 | 'type': 'fixed_time_per_day', 47 | 'time_zone': 'UTC', 48 | 'days_of_week': [1, 2, 3, 4, 5], 49 | 'start_time': '09:00:00', 50 | 'end_time': '17:00:00' 51 | } 52 | INTEGRATIONS = [] 53 | ADDONS = [] 54 | 55 | 56 | def create_service(): 57 | url = 'https://api.pagerduty.com/services' 58 | headers = { 59 | 'Accept': 'application/vnd.pagerduty+json;version=2', 60 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 61 | 'Content-type': 'application/json' 62 | } 63 | payload = { 64 | 'service': { 65 | 'name': NAME, 66 | 'description': DESCRIPTION, 67 | 'escalation_policy': { 68 | 'id': ESCALATION_POLICY_ID, 69 | 'type': 'escalation_policy' 70 | }, 71 | 'type': TYPE, 72 | 'auto_resolve_timeout': AUTO_RESOLVE_TIMEOUT, 73 | 'acknowledgement_timeout': ACKNOWLEDGEMENT_TIMEOUT, 74 | 'teams': TEAMS, 75 | 'scheduled_actions': SCHEDULED_ACTIONS, 76 | 'integrations': INTEGRATIONS, 77 | 'addons': ADDONS, 78 | 'support_hours': SUPPORT_HOURS 79 | } 80 | } 81 | if not SUPPORT_HOURS: 82 | payload['service']['incident_urgency_rule'] = { 83 | 'type': 'constant', 84 | 'urgency': INCIDENT_URGENCY 85 | } 86 | else: 87 | payload['service']['incident_urgency_rule'] = { 88 | 'type': 'use_support_hours', 89 | 'during_support_hours': { 90 | 'type': 'constant', 91 | 'urgency': INCIDENT_URGENCY 92 | }, 93 | 'outside_support_hours': { 94 | 'type': 'constant', 95 | 'urgency': OUTSIDE_SUPPORT_HOURS_URGENCY 96 | } 97 | } 98 | r = requests.post(url, headers=headers, data=json.dumps(payload)) 99 | print('Status Code: {code}'.format(code=r.status_code)) 100 | print(r.json()) 101 | 102 | if __name__ == '__main__': 103 | create_service() 104 | -------------------------------------------------------------------------------- /REST_API_v2/Services/delete_service.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match ID of resource you want to delete 34 | ID = 'PTRCGYM' 35 | 36 | 37 | def delete_service(): 38 | url = 'https://api.pagerduty.com/services/{id}'.format(id=ID) 39 | headers = { 40 | 'Accept': 'application/vnd.pagerduty+json;version=2', 41 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 42 | } 43 | r = requests.delete(url, headers=headers) 44 | print('Status Code: {code}'.format(code=r.status_code)) 45 | print(r.text) 46 | 47 | if __name__ == '__main__': 48 | delete_service() 49 | -------------------------------------------------------------------------------- /REST_API_v2/Services/get_integration.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your service and integration IDs 34 | SERVICE_ID = 'PAU38PJ' 35 | INTEGRATION_ID = 'PTT2FMS' 36 | 37 | # Update to match your chosen parameters 38 | INCLUDE = [] 39 | 40 | 41 | def get_integration(): 42 | url = 'https://api.pagerduty.com/services/{sid}/integrations/{iid}'.format( 43 | sid=SERVICE_ID, 44 | iid=INTEGRATION_ID 45 | ) 46 | headers = { 47 | 'Accept': 'application/vnd.pagerduty+json;version=2', 48 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 49 | } 50 | payload = { 51 | 'include[]': INCLUDE 52 | } 53 | r = requests.get(url, headers=headers, params=payload) 54 | print('Status Code: {code}'.format(code=r.status_code)) 55 | print(r.json()) 56 | 57 | if __name__ == '__main__': 58 | get_integration() 59 | -------------------------------------------------------------------------------- /REST_API_v2/Services/get_service.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your service ID 34 | ID = 'PKWA90D' 35 | 36 | # Update to match your chosen parameters 37 | INCLUDE = [] 38 | 39 | 40 | def get_service(): 41 | url = 'https://api.pagerduty.com/services/{id}'.format(id=ID) 42 | headers = { 43 | 'Accept': 'application/vnd.pagerduty+json;version=2', 44 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 45 | } 46 | payload = { 47 | 'include[]': INCLUDE 48 | } 49 | r = requests.get(url, headers=headers, params=payload) 50 | print('Status Code: {code}'.format(code=r.status_code)) 51 | print(r.json()) 52 | 53 | if __name__ == '__main__': 54 | get_service() 55 | -------------------------------------------------------------------------------- /REST_API_v2/Services/list_services.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your chosen parameters 34 | TEAM_IDS = [] 35 | TIME_ZONE = 'UTC' 36 | SORT_BY = 'name' 37 | QUERY = '' 38 | INCLUDE = [] 39 | 40 | 41 | def list_services(): 42 | url = 'https://api.pagerduty.com/services' 43 | headers = { 44 | 'Accept': 'application/vnd.pagerduty+json;version=2', 45 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 46 | } 47 | payload = { 48 | 'team_ids[]': TEAM_IDS, 49 | 'time_zone': TIME_ZONE, 50 | 'sort_by': SORT_BY, 51 | 'query': QUERY, 52 | 'include[]': INCLUDE 53 | } 54 | r = requests.get(url, headers=headers, params=payload) 55 | print('Status Code: {code}'.format(code=r.status_code)) 56 | print(r.json()) 57 | 58 | if __name__ == '__main__': 59 | list_services() 60 | -------------------------------------------------------------------------------- /REST_API_v2/Services/update_integration.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match ID of resource you want to update 35 | SERVICE_ID = 'PAU38PJ' 36 | INTEGRATION_ID = 'PTT2FMS' 37 | 38 | # Update to match your chosen parameters 39 | NAME = 'Insert your integration name here' 40 | SUMMARY = 'Insert your integration summary here' 41 | 42 | 43 | def update_integration(): 44 | url = 'https://api.pagerduty.com/services/{sid}/integrations/{iid}'.format( 45 | sid=SERVICE_ID, 46 | iid=INTEGRATION_ID 47 | ) 48 | headers = { 49 | 'Accept': 'application/vnd.pagerduty+json;version=2', 50 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 51 | 'Content-type': 'application/json' 52 | } 53 | payload = { 54 | 'integration': { 55 | 'name': NAME, 56 | 'summary': SUMMARY 57 | } 58 | } 59 | r = requests.put(url, headers=headers, data=json.dumps(payload)) 60 | print('Status Code: {code}'.format(code=r.status_code)) 61 | print(r.json()) 62 | 63 | if __name__ == '__main__': 64 | update_integration() 65 | -------------------------------------------------------------------------------- /REST_API_v2/Services/update_service.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match ID of resource you want to update 35 | ID = 'P8RK2P8' 36 | 37 | # Update to match your chosen parameters 38 | NAME = 'Insert your service name here' 39 | DESCRIPTION = 'Insert your service description here' 40 | ESCALATION_POLICY_ID = 'PIX2DN3' 41 | ACKNOWLEDGEMENT_TIMEOUT = 60 * 30 # 30 minutes 42 | AUTO_RESOLVE_TIMEOUT = 60 * 60 * 4 # 4 hours 43 | SEVERITY_FILTER = '' 44 | 45 | 46 | def update_service(): 47 | url = 'https://api.pagerduty.com/services/{id}'.format(id=ID) 48 | headers = { 49 | 'Accept': 'application/vnd.pagerduty+json;version=2', 50 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 51 | 'Content-type': 'application/json' 52 | } 53 | payload = { 54 | 'service': { 55 | 'name': NAME, 56 | 'description': DESCRIPTION, 57 | 'escalation_policy': { 58 | 'id': ESCALATION_POLICY_ID, 59 | 'type': 'escalation_policy_reference' 60 | }, 61 | 'acknowledgement_timeout': ACKNOWLEDGEMENT_TIMEOUT, 62 | 'auto_resolve_timeout': AUTO_RESOLVE_TIMEOUT, 63 | 'severity_filter': SEVERITY_FILTER 64 | } 65 | } 66 | r = requests.put(url, headers=headers, data=json.dumps(payload)) 67 | print('Status Code: {code}'.format(code=r.status_code)) 68 | print(r.json()) 69 | 70 | if __name__ == '__main__': 71 | update_service() 72 | -------------------------------------------------------------------------------- /REST_API_v2/Teams/add_escalation_policy_to_team.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your IDs 34 | TEAM_ID = 'PYYWGIO' 35 | ESCALATION_POLICY_ID = 'PZPCKNC' 36 | 37 | 38 | def add_escalation_policy_to_team(): 39 | url = ('https://api.pagerduty.com/teams/{tid}/escalation_policies/{eid}' 40 | .format(tid=TEAM_ID, eid=ESCALATION_POLICY_ID)) 41 | headers = { 42 | 'Accept': 'application/vnd.pagerduty+json;version=2', 43 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 44 | 'Content-type': 'application/json' 45 | } 46 | r = requests.put(url, headers=headers) 47 | print('Status Code: {code}'.format(code=r.status_code)) 48 | print(r.text) 49 | 50 | if __name__ == '__main__': 51 | add_escalation_policy_to_team() 52 | -------------------------------------------------------------------------------- /REST_API_v2/Teams/add_user_to_team.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '' 32 | 33 | # Update to match your IDs 34 | TEAM_ID = '' 35 | USER_ID = '' 36 | 37 | 38 | def add_user_to_team(): 39 | url = 'https://api.pagerduty.com/teams/{tid}/users/{uid}'.format( 40 | tid=TEAM_ID, 41 | uid=USER_ID 42 | ) 43 | headers = { 44 | 'Accept': 'application/vnd.pagerduty+json;version=2', 45 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 46 | 'Content-type': 'application/json' 47 | } 48 | r = requests.put(url, headers=headers) 49 | print('Status Code: {code}'.format(code=r.status_code)) 50 | print(r.text) 51 | 52 | if __name__ == '__main__': 53 | add_user_to_team() 54 | -------------------------------------------------------------------------------- /REST_API_v2/Teams/create_team.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match your chosen parameters 35 | NAME = 'Insert team name here' 36 | DESCRIPTION = 'Insert team description here' 37 | 38 | 39 | def create_team(): 40 | url = 'https://api.pagerduty.com/teams' 41 | headers = { 42 | 'Accept': 'application/vnd.pagerduty+json;version=2', 43 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 44 | 'Content-type': 'application/json' 45 | } 46 | payload = { 47 | 'team': { 48 | 'type': 'team', 49 | 'name': NAME, 50 | 'description': DESCRIPTION, 51 | 'summary': DESCRIPTION 52 | } 53 | } 54 | r = requests.post(url, headers=headers, data=json.dumps(payload)) 55 | print('Status Code: {code}'.format(code=r.status_code)) 56 | print(r.json()) 57 | 58 | if __name__ == '__main__': 59 | create_team() 60 | -------------------------------------------------------------------------------- /REST_API_v2/Teams/delete_team.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match ID of resource you want to delete 34 | ID = 'P53LIBV' 35 | 36 | 37 | def delete_team(): 38 | url = 'https://api.pagerduty.com/teams/{id}'.format(id=ID) 39 | headers = { 40 | 'Accept': 'application/vnd.pagerduty+json;version=2', 41 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 42 | } 43 | r = requests.delete(url, headers=headers) 44 | print('Status Code: {code}'.format(code=r.status_code)) 45 | print(r.text) 46 | 47 | if __name__ == '__main__': 48 | delete_team() 49 | -------------------------------------------------------------------------------- /REST_API_v2/Teams/get_team.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your team ID 34 | ID = 'PD28XX6' 35 | 36 | 37 | def get_team(): 38 | url = 'https://api.pagerduty.com/teams/{id}'.format(id=ID) 39 | headers = { 40 | 'Accept': 'application/vnd.pagerduty+json;version=2', 41 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 42 | } 43 | r = requests.get(url, headers=headers) 44 | print('Status Code: {code}'.format(code=r.status_code)) 45 | print(r.json()) 46 | 47 | if __name__ == '__main__': 48 | get_team() 49 | -------------------------------------------------------------------------------- /REST_API_v2/Teams/list_teams.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your chosen parameters 34 | QUERY = '' 35 | 36 | 37 | def list_teams(): 38 | url = 'https://api.pagerduty.com/teams' 39 | headers = { 40 | 'Accept': 'application/vnd.pagerduty+json;version=2', 41 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 42 | } 43 | payload = { 44 | 'query': QUERY 45 | } 46 | r = requests.get(url, headers=headers, params=payload) 47 | print('Status Code: {code}'.format(code=r.status_code)) 48 | print(r.json()) 49 | 50 | if __name__ == '__main__': 51 | list_teams() 52 | -------------------------------------------------------------------------------- /REST_API_v2/Teams/remove_escalation_policy_from_team.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your IDs 34 | TEAM_ID = 'PYYWGIO' 35 | ESCALATION_POLICY_ID = 'PZPCKNC' 36 | 37 | 38 | def remove_escalation_policy_from_team(): 39 | url = ('https://api.pagerduty.com/teams/{tid}/escalation_policies/{eid}' 40 | .format(tid=TEAM_ID, eid=ESCALATION_POLICY_ID)) 41 | headers = { 42 | 'Accept': 'application/vnd.pagerduty+json;version=2', 43 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 44 | } 45 | r = requests.delete(url, headers=headers) 46 | print('Status Code: {code}'.format(code=r.status_code)) 47 | print(r.text) 48 | 49 | if __name__ == '__main__': 50 | remove_escalation_policy_from_team() 51 | -------------------------------------------------------------------------------- /REST_API_v2/Teams/remove_user_from_team.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your IDs 34 | TEAM_ID = 'PYYWGIO' 35 | USER_ID = 'P0H7Y7J' 36 | 37 | 38 | def remove_user_from_team(): 39 | url = 'https://api.pagerduty.com/teams/{tid}/users/{uid}'.format( 40 | tid=TEAM_ID, 41 | uid=USER_ID 42 | ) 43 | headers = { 44 | 'Accept': 'application/vnd.pagerduty+json;version=2', 45 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 46 | } 47 | r = requests.delete(url, headers=headers) 48 | print('Status Code: {code}'.format(code=r.status_code)) 49 | print(r.text) 50 | 51 | if __name__ == '__main__': 52 | remove_user_from_team() 53 | -------------------------------------------------------------------------------- /REST_API_v2/Teams/update_team.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match ID of resource you want to update 35 | ID = 'PYYWGIO' 36 | 37 | # Update to match your chosen parameters 38 | NAME = 'Insert your team name here' 39 | DESCRIPTION = 'Insert your team description here' 40 | 41 | 42 | def update_team(): 43 | url = 'https://api.pagerduty.com/teams/{id}'.format(id=ID) 44 | headers = { 45 | 'Accept': 'application/vnd.pagerduty+json;version=2', 46 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 47 | 'Content-type': 'application/json' 48 | } 49 | payload = { 50 | 'team': { 51 | 'name': NAME, 52 | 'description': DESCRIPTION 53 | } 54 | } 55 | r = requests.put(url, headers=headers, data=json.dumps(payload)) 56 | print('Status Code: {code}'.format(code=r.status_code)) 57 | print(r.json()) 58 | 59 | if __name__ == '__main__': 60 | update_team() 61 | -------------------------------------------------------------------------------- /REST_API_v2/Users/create_user.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match your PagerDuty email address 35 | PD_EMAIL = 'lucas@pagerduty.com' 36 | 37 | # Update to match your chosen parameters for the new user 38 | NAME = 'Insert user name here' 39 | EMAIL = 'insert_email@here.com' 40 | ROLE = 'user' # Can be one of admin, user, limited_user, read_only_user # NOQA 41 | 42 | 43 | def create_user(): 44 | url = 'https://api.pagerduty.com/users' 45 | headers = { 46 | 'Accept': 'application/vnd.pagerduty+json;version=2', 47 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 48 | 'Content-type': 'application/json', 49 | 'From': PD_EMAIL 50 | } 51 | payload = { 52 | 'user': { 53 | 'type': 'user', 54 | 'name': NAME, 55 | 'email': EMAIL, 56 | 'role': ROLE 57 | } 58 | } 59 | r = requests.post(url, headers=headers, data=json.dumps(payload)) 60 | print('Status Code: {code}'.format(code=r.status_code)) 61 | print(r.json()) 62 | 63 | if __name__ == '__main__': 64 | create_user() 65 | -------------------------------------------------------------------------------- /REST_API_v2/Users/create_user_contact_method.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match ID of user you want to update 35 | ID = 'P0H7Y7J' 36 | 37 | # Update to match your chosen parameters 38 | TYPE = 'email_contact_method' # Can be one of email_contact_method, sms_contact_method, phone_contact_method, or push_notification_contact_method # NOQA 39 | ADDRESS = 'insert_email@here.com' 40 | LABEL = 'Work' 41 | 42 | 43 | def create_user_contact_method(): 44 | url = 'https://api.pagerduty.com/users/{id}/contact_methods'.format(id=ID) 45 | headers = { 46 | 'Accept': 'application/vnd.pagerduty+json;version=2', 47 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 48 | 'Content-type': 'application/json' 49 | } 50 | payload = { 51 | 'contact_method': { 52 | 'type': TYPE, 53 | 'address': ADDRESS, 54 | 'label': LABEL 55 | } 56 | } 57 | r = requests.post(url, headers=headers, data=json.dumps(payload)) 58 | print('Status Code: {code}'.format(code=r.status_code)) 59 | print(r.json()) 60 | 61 | if __name__ == '__main__': 62 | create_user_contact_method() 63 | -------------------------------------------------------------------------------- /REST_API_v2/Users/create_user_notification_rule.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match ID of user you want to update 35 | ID = 'P0TEZR0' 36 | 37 | # Update to match your chosen parameters 38 | START_DELAY_IN_MINUTES = '5' 39 | URGENCY = 'high' 40 | CONTACT_METHOD_ID = 'P54SUEP' 41 | CONTACT_METHOD_TYPE = 'email_contact_method' 42 | 43 | 44 | def create_user_notification_rule(): 45 | url = 'https://api.pagerduty.com/users/{id}/notification_rules'.format( 46 | id=ID 47 | ) 48 | headers = { 49 | 'Accept': 'application/vnd.pagerduty+json;version=2', 50 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 51 | 'Content-type': 'application/json' 52 | } 53 | payload = { 54 | 'notification_rule': { 55 | 'start_delay_in_minutes': START_DELAY_IN_MINUTES, 56 | 'contact_method': { 57 | 'id': CONTACT_METHOD_ID, 58 | 'type': CONTACT_METHOD_TYPE 59 | }, 60 | 'type': 'assignment_notification_rule', 61 | 'urgency': URGENCY 62 | } 63 | } 64 | r = requests.post(url, headers=headers, data=json.dumps(payload)) 65 | print('Status Code: {code}'.format(code=r.status_code)) 66 | print(r.json()) 67 | 68 | if __name__ == '__main__': 69 | create_user_notification_rule() 70 | -------------------------------------------------------------------------------- /REST_API_v2/Users/delete_user.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match ID of resource you want to delete 34 | ID = 'PK1VFD9' 35 | 36 | 37 | def delete_user(): 38 | url = 'https://api.pagerduty.com/users/{id}'.format(id=ID) 39 | headers = { 40 | 'Accept': 'application/vnd.pagerduty+json;version=2', 41 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 42 | } 43 | r = requests.delete(url, headers=headers) 44 | print('Status Code: {code}'.format(code=r.status_code)) 45 | print(r.text) 46 | 47 | if __name__ == '__main__': 48 | delete_user() 49 | -------------------------------------------------------------------------------- /REST_API_v2/Users/delete_user_contact_method.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your IDs 34 | USER_ID = 'P0TEZR0' 35 | CONTACT_METHOD_ID = 'PRP8EDZ' 36 | 37 | 38 | def delete_user_contact_method(): 39 | url = 'https://api.pagerduty.com/users/{uid}/contact_methods/{cid}'.format( 40 | uid=USER_ID, 41 | cid=CONTACT_METHOD_ID 42 | ) 43 | headers = { 44 | 'Accept': 'application/vnd.pagerduty+json;version=2', 45 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 46 | } 47 | r = requests.delete(url, headers=headers) 48 | print('Status Code: {code}'.format(code=r.status_code)) 49 | print(r.text) 50 | 51 | if __name__ == '__main__': 52 | delete_user_contact_method() 53 | -------------------------------------------------------------------------------- /REST_API_v2/Users/delete_user_notification_rule.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your IDs 34 | USER_ID = 'P0TEZR0' 35 | NOTIFICATION_RULE_ID = 'PM0NWL3' 36 | 37 | 38 | def delete_user_notification_rule(): 39 | url = ('https://api.pagerduty.com/users/{uid}/notification_rules/{nid}' 40 | .format(uid=USER_ID, nid=NOTIFICATION_RULE_ID)) 41 | headers = { 42 | 'Accept': 'application/vnd.pagerduty+json;version=2', 43 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 44 | } 45 | r = requests.delete(url, headers=headers) 46 | print('Status Code: {code}'.format(code=r.status_code)) 47 | print(r.text) 48 | 49 | if __name__ == '__main__': 50 | delete_user_notification_rule() 51 | -------------------------------------------------------------------------------- /REST_API_v2/Users/get_user.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your user ID 34 | ID = 'P0TEZR0' 35 | 36 | # Update to match your chosen parameters 37 | INCLUDE = [] 38 | 39 | 40 | def get_user(): 41 | url = 'https://api.pagerduty.com/users/{id}'.format(id=ID) 42 | headers = { 43 | 'Accept': 'application/vnd.pagerduty+json;version=2', 44 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 45 | } 46 | payload = { 47 | 'include[]': INCLUDE 48 | } 49 | r = requests.get(url, headers=headers, params=payload) 50 | print('Status Code: {code}'.format(code=r.status_code)) 51 | print(r.json()) 52 | 53 | if __name__ == '__main__': 54 | get_user() 55 | -------------------------------------------------------------------------------- /REST_API_v2/Users/get_user_contact_method.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your IDs 34 | USER_ID = 'P0TEZR0' 35 | CONTACT_METHOD_ID = 'P54SUEP' 36 | 37 | 38 | def get_user_contact_method(): 39 | url = 'https://api.pagerduty.com/users/{uid}/contact_methods/{cid}'.format( 40 | uid=USER_ID, 41 | cid=CONTACT_METHOD_ID 42 | ) 43 | headers = { 44 | 'Accept': 'application/vnd.pagerduty+json;version=2', 45 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 46 | } 47 | r = requests.get(url, headers=headers) 48 | print('Status Code: {code}'.format(code=r.status_code)) 49 | print(r.json()) 50 | 51 | if __name__ == '__main__': 52 | get_user_contact_method() 53 | -------------------------------------------------------------------------------- /REST_API_v2/Users/get_user_notification_rule.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your IDs 34 | USER_ID = 'P0TEZR0' 35 | NOTIFICATION_RULE_ID = 'PCR2WKT' 36 | 37 | # Update to match your chosen parameters 38 | INCLUDE = [] 39 | 40 | 41 | def get_user_notification_rule(): 42 | url = ('https://api.pagerduty.com/users/{uid}/notification_rules/{nid}' 43 | .format(uid=USER_ID, nid=NOTIFICATION_RULE_ID)) 44 | headers = { 45 | 'Accept': 'application/vnd.pagerduty+json;version=2', 46 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 47 | } 48 | payload = { 49 | 'include[]': INCLUDE 50 | } 51 | r = requests.get(url, headers=headers, params=payload) 52 | print('Status Code: {code}'.format(code=r.status_code)) 53 | print(r.json()) 54 | 55 | if __name__ == '__main__': 56 | get_user_notification_rule() 57 | -------------------------------------------------------------------------------- /REST_API_v2/Users/list_user_contact_methods.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your user ID 34 | ID = 'P0TEZR0' 35 | 36 | 37 | def list_user_contact_methods(): 38 | url = 'https://api.pagerduty.com/users/{id}/contact_methods'.format(id=ID) 39 | headers = { 40 | 'Accept': 'application/vnd.pagerduty+json;version=2', 41 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 42 | } 43 | r = requests.get(url, headers=headers) 44 | print('Status Code: {code}'.format(code=r.status_code)) 45 | print(r.json()) 46 | 47 | if __name__ == '__main__': 48 | list_user_contact_methods() 49 | -------------------------------------------------------------------------------- /REST_API_v2/Users/list_user_notification_rules.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your user ID 34 | ID = 'P0TEZR0' 35 | 36 | # Update to match your chosen parameters 37 | INCLUDE = [] 38 | 39 | 40 | def list_user_notification_rules(): 41 | url = 'https://api.pagerduty.com/users/{id}/notification_rules'.format( 42 | id=ID 43 | ) 44 | headers = { 45 | 'Accept': 'application/vnd.pagerduty+json;version=2', 46 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 47 | } 48 | payload = { 49 | 'include[]': INCLUDE 50 | } 51 | r = requests.get(url, headers=headers, params=payload) 52 | print('Status Code: {code}'.format(code=r.status_code)) 53 | print(r.json()) 54 | 55 | if __name__ == '__main__': 56 | list_user_notification_rules() 57 | -------------------------------------------------------------------------------- /REST_API_v2/Users/list_users.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your chosen parameters 34 | QUERY = '' 35 | TEAM_IDS = [] 36 | INCLUDE = [] 37 | 38 | 39 | def list_users(): 40 | url = 'https://api.pagerduty.com/users' 41 | headers = { 42 | 'Accept': 'application/vnd.pagerduty+json;version=2', 43 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 44 | } 45 | payload = { 46 | 'query': QUERY, 47 | 'team_ids[]': TEAM_IDS, 48 | 'include[]': INCLUDE 49 | } 50 | r = requests.get(url, headers=headers, params=payload) 51 | print('Status Code: {code}'.format(code=r.status_code)) 52 | print(r.json()) 53 | 54 | if __name__ == '__main__': 55 | list_users() 56 | -------------------------------------------------------------------------------- /REST_API_v2/Users/update_user.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match ID of resource you want to update 35 | ID = 'P0TEZR0' 36 | 37 | # Update to match your chosen parameters 38 | NAME = 'Insert user name here' 39 | EMAIL = 'insert_email@here.com' 40 | ROLE = 'user' # Can be one of admin, user, limited_user, read_only_user # NOQA 41 | 42 | 43 | def update_user(): 44 | url = 'https://api.pagerduty.com/users/{id}'.format(id=ID) 45 | headers = { 46 | 'Accept': 'application/vnd.pagerduty+json;version=2', 47 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 48 | 'Content-type': 'application/json' 49 | } 50 | payload = { 51 | 'user': { 52 | 'name': NAME, 53 | 'email': EMAIL, 54 | 'role': ROLE 55 | } 56 | } 57 | r = requests.put(url, headers=headers, data=json.dumps(payload)) 58 | print('Status Code: {code}'.format(code=r.status_code)) 59 | print(r.json()) 60 | 61 | if __name__ == '__main__': 62 | update_user() 63 | -------------------------------------------------------------------------------- /REST_API_v2/Users/update_user_contact_method.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match your IDs 35 | USER_ID = 'P0TEZR0' 36 | CONTACT_METHOD_ID = 'P54SUEP' 37 | 38 | # Update to match your chosen parameters 39 | TYPE = 'email_contact_method' # Can be one of email_contact_method, sms_contact_method, phone_contact_method, or push_notification_contact_method # NOQA 40 | ADDRESS = 'insert_email@here.com' 41 | LABEL = 'Work' 42 | 43 | 44 | def update_user_contact_method(): 45 | url = 'https://api.pagerduty.com/users/{uid}/contact_methods/{cid}'.format( 46 | uid=USER_ID, 47 | cid=CONTACT_METHOD_ID 48 | ) 49 | headers = { 50 | 'Accept': 'application/vnd.pagerduty+json;version=2', 51 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 52 | 'Content-type': 'application/json' 53 | } 54 | payload = { 55 | 'contact_method': { 56 | 'type': TYPE, 57 | 'address': ADDRESS, 58 | 'label': LABEL 59 | } 60 | } 61 | r = requests.put(url, headers=headers, data=json.dumps(payload)) 62 | print('Status Code: {code}'.format(code=r.status_code)) 63 | print(r.json()) 64 | 65 | if __name__ == '__main__': 66 | update_user_contact_method() 67 | -------------------------------------------------------------------------------- /REST_API_v2/Users/update_user_notification_rule.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | import json 30 | 31 | # Update to match your API key 32 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 33 | 34 | # Update to match your IDs 35 | USER_ID = 'P0TEZR0' 36 | NOTIFICATION_RULE_ID = 'PHK9WYE' 37 | 38 | # Update to match your chosen parameters 39 | START_DELAY_IN_MINUTES = '3' 40 | URGENCY = 'high' 41 | CONTACT_METHOD_ID = 'P54SUEP' 42 | CONTACT_METHOD_TYPE = 'email_contact_method' 43 | 44 | 45 | def update_user_notification_rule(): 46 | url = ('https://api.pagerduty.com/users/{uid}/notification_rules/{nid}' 47 | .format(uid=USER_ID, nid=NOTIFICATION_RULE_ID)) 48 | headers = { 49 | 'Accept': 'application/vnd.pagerduty+json;version=2', 50 | 'Authorization': 'Token token={token}'.format(token=API_KEY), 51 | 'Content-type': 'application/json' 52 | } 53 | payload = { 54 | 'notification_rule': { 55 | 'type': 'assignment_notification_rule', 56 | 'start_delay_in_minutes': START_DELAY_IN_MINUTES, 57 | 'urgency': URGENCY, 58 | 'contact_method': { 59 | 'id': CONTACT_METHOD_ID, 60 | 'type': CONTACT_METHOD_TYPE 61 | } 62 | } 63 | } 64 | r = requests.put(url, headers=headers, data=json.dumps(payload)) 65 | print('Status Code: {code}'.format(code=r.status_code)) 66 | print(r.json()) 67 | 68 | if __name__ == '__main__': 69 | update_user_notification_rule() 70 | -------------------------------------------------------------------------------- /REST_API_v2/Vendors/get_vendor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | # Update to match your vendor ID 34 | ID = 'PYFMET1' 35 | 36 | 37 | def get_vendor(): 38 | url = 'https://api.pagerduty.com/vendors/{id}'.format(id=ID) 39 | headers = { 40 | 'Accept': 'application/vnd.pagerduty+json;version=2', 41 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 42 | } 43 | r = requests.get(url, headers=headers) 44 | print('Status Code: {code}'.format(code=r.status_code)) 45 | print('r.json()) 46 | 47 | if __name__ == '__main__': 48 | get_vendor() 49 | -------------------------------------------------------------------------------- /REST_API_v2/Vendors/list_vendors.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2016, PagerDuty, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of PagerDuty Inc nor the 14 | # names of its contributors may be used to endorse or promote products 15 | # derived from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | import requests 29 | 30 | # Update to match your API key 31 | API_KEY = '3c3gRvzx7uGfMYEnWKvF' 32 | 33 | 34 | def list_vendors(): 35 | url = 'https://api.pagerduty.com/vendors' 36 | headers = { 37 | 'Accept': 'application/vnd.pagerduty+json;version=2', 38 | 'Authorization': 'Token token={token}'.format(token=API_KEY) 39 | } 40 | r = requests.get(url, headers=headers) 41 | print('Status Code: {code}'.format(code=r.status_code)) 42 | print(r.json()) 43 | 44 | if __name__ == '__main__': 45 | list_vendors() 46 | --------------------------------------------------------------------------------