# Set API tokenexportPDTOKEN="your_api_token_here"# Set default region (for EU accounts)exportPD_API_BASE="https://api.eu.pagerduty.com"# Set default user emailexportPD_USER_EMAIL="user@example.com"
# Integration keys are service-specific# Find them at: Service → Integrations → Integration Key# Use in agent:pd-send-k"your_integration_key"-ttrigger-d"Alert message"# Use in Events API v2:curl-XPOSThttps://events.pagerduty.com/v2/enqueue\-H"Content-Type: application/json"\-d'{ "routing_key": "your_integration_key", "event_action": "trigger", "payload": { "summary": "Server down", "severity": "critical", "source": "prod-server-01" } }'
{"service":{"name":"Production API","description":"Main production API service","escalation_policy":{"id":"ESCALATION_POLICY_ID","type":"escalation_policy_reference"},"alert_creation":"create_alerts_and_incidents","incident_urgency_rule":{"type":"constant","urgency":"high"},"auto_resolve_timeout":14400,"acknowledgement_timeout":1800}}
Use Case 1: Trigger and Resolve Incident from Monitoring¶
# Trigger incident when issue detectedpd-send-kR0123456789ABCDEF0123456789ABCDEF\-ttrigger\-d"Database connection pool exhausted"\-scritical\-idb_pool_incident_001
# Add context as incident developspd-send-kR0123456789ABCDEF0123456789ABCDEF\-ttrigger\-d"Connection count: 500/500"\-idb_pool_incident_001
# Resolve when fixedpd-send-kR0123456789ABCDEF0123456789ABCDEF\-tresolve\-idb_pool_incident_001
Use Case 2: Check Who's On-Call Before Deployment¶
# Get current on-call engineerspdoncall:list--json|jq-r'.oncalls[] | "\(.escalation_policy.summary): \(.user.summary)"'# Get on-call for specific escalation policypdoncall:list--escalation-policy-idsEP123456--json|jq-r'.oncalls[].user.summary'# Check schedule for next 7 dayspdschedule:show--idSCHEDULE_ID--since$(date-u+%Y-%m-%dT%H:%M:%SZ)--until$(date-u-d'+7 days'+%Y-%m-%dT%H:%M:%SZ)
Use Case 3: Bulk Incident Management During Outage¶
# Get all triggered incidents for a serviceINCIDENTS=$(pdincident:list--service-idsSERVICE_ID--statustriggered--json|jq-r'.incidents[].id')# Acknowledge all incidentsecho"$INCIDENTS"|xargs-I{}pdincident:ack--id{}# Add note to all incidentsecho"$INCIDENTS"|xargs-I{}pdincident:notes--id{}--note"Mass outage - investigating root cause"# Resolve all incidents after fixecho"$INCIDENTS"|xargs-I{}pdincident:resolve--id{}
Use Case 4: Create Incident with Conference Bridge¶
# Get incidents from last weekLAST_WEEK=$(date-u-d'7 days ago'+%Y-%m-%dT%H:%M:%SZ)NOW=$(date-u+%Y-%m-%dT%H:%M:%SZ)pdincident:list--since$LAST_WEEK--until$NOW--json|\jq-r'.incidents[] | [.created_at, .urgency, .status, .title] | @csv'>weekly_incidents.csv
# Count incidents by servicepdincident:list--since$LAST_WEEK--until$NOW--json|\jq-r'.incidents[] | .service.summary'|sort|uniq-c|sort-rn
# Calculate mean time to acknowledgepdincident:list--since$LAST_WEEK--until$NOW--json|\jq'[.incidents[] | select(.status == "resolved") | (.first_trigger_log_entry.created_at as $trigger | .acknowledgements[0].at as $ack | ($ack | fromdateiso8601) - ($trigger | fromdateiso8601))] | add / length / 60'# Result in minutes
Verify token with pd rest:get /users/me. Generate new token at Configuration → API Access. Ensure token has correct permissions.
Agent not sending events
Check agent status: sudo systemctl status pdagent. View logs: sudo journalctl -u pdagent -f. Verify integration key is correct. Test connectivity: curl https://events.pagerduty.com/health
Incidents not triggering
Verify service is enabled: pd service:get --id SERVICE_ID. Check integration key matches. Ensure service has valid escalation policy assigned.
No notifications received
Check user contact methods: pd user:contact:list --user-id USER_ID. Verify notification rules: pd user:notification:list --user-id USER_ID. Test contact method in PagerDuty UI.
CLI returns "Service Unavailable"
Check PagerDuty status at status.pagerduty.com. Verify API endpoint (use https://api.eu.pagerduty.com for EU accounts). Check network connectivity and firewall rules.
Duplicate incidents created
Use consistent incident keys with -i flag. Configure alert grouping in service settings. Set appropriate deduplication time windows.
Schedule shows wrong on-call person
Verify timezone settings in schedule configuration. Check for active overrides: pd schedule:show --id SCHEDULE_ID. Ensure schedule layers are configured correctly.
API rate limit exceeded
Implement exponential backoff in scripts. Use bulk operations where possible. Cache frequently accessed data. Check rate limit headers in API responses.