Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow passing empty scheduled actions #468

Open
cluarkhpe opened this issue Oct 24, 2022 · 1 comment · May be fixed by #549
Open

allow passing empty scheduled actions #468

cluarkhpe opened this issue Oct 24, 2022 · 1 comment · May be fixed by #549

Comments

@cluarkhpe
Copy link
Contributor

the following code to create a service will fail with an error saying that scheduled actions must be specified:

_, err = pagerdutyClient.CreateServiceWithContext(context.Background(), pagerduty.Service{
                Name:             "testlibfailservice",
                Description:      "for testing lib failures",
                EscalationPolicy: *escalationPolicy,
                AlertCreation:    "create_alerts_and_incidents",
                IncidentUrgencyRule: &pagerduty.IncidentUrgencyRule{
                        Type:    "use_support_hours",
                        Urgency: "severity_based",
                        DuringSupportHours: &pagerduty.IncidentUrgencyType{
                                Type:    "constant",
                                Urgency: "high",
                        },
                        OutsideSupportHours: &pagerduty.IncidentUrgencyType{
                                Type:    "constant",
                                Urgency: "low",
                        },
                },
                SupportHours: &pagerduty.SupportHours{
                        Type:       "fixed_time_per_day",
                        Timezone:   "America/Lima",
                        StartTime:  "09:00:00",
                        EndTime:    "17:00:00",
                        DaysOfWeek: []uint{1, 2, 3, 4, 5},
                },
                ScheduledActions: []pagerduty.ScheduledAction{},
        })

a direct call to the api with the same inputs works
curl -X POST --data "@service.json" -H "Authorization: Token token=$PAGERDUTY_TOKEN" -H "Content-Type: application/json" https://api.pagerduty.com/services
service.json:

{
  "service": {
    "name": "testapifailservice",
    "description": "for testing api",
    "alert_creation": "create_alerts_and_incidents",
    "scheduled_actions": [],
    "support_hours": {
      "type": "fixed_time_per_day",
      "time_zone": "America/Lima",
      "days_of_week": [
        1,
        2,
        3,
        4,
        5
      ],
      "start_time": "09:00:00",
      "end_time": "17:00:00"
    },
    "escalation_policy": {
      "id": "<ESCALATION_POLICY_ID>",
      "type": "escalation_policy_reference"
    },
    "incident_urgency_rule": {
      "type": "use_support_hours",
      "during_support_hours": {
        "type": "constant",
        "urgency": "high"
      },
      "outside_support_hours": {
        "type": "constant",
        "urgency": "low"
      }
    },
    "type": "service"
  }
}
@pw-mdb
Copy link

pw-mdb commented Feb 5, 2025

We're running into this too. Fix: #549

pw-mdb added a commit to pw-mdb/go-pagerduty that referenced this issue Feb 5, 2025
Fixes PagerDuty#468. When `Service.SupportHours` is specified, `Service.ScheduledActions` is required, otherwise the PagerDuty API returns the following error:

```
HTTP response failed with status code 400, message: Invalid Input Provided (code: 2001): Scheduled actions is required.
```

This implements a custom `MarshalJSON` function for `Service`, which ignores `ScheduledActions`'s `omitempty` when `SupportHours` is specified, and enforces it otherwise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants