PagerDuty / go-pagerduty

go client library for PagerDuty v2 API
https://v2.developer.pagerduty.com/docs/rest-api
Apache License 2.0
287 stars 240 forks source link

Fix parsing bug for AlertGroupingParameters #448

Closed mjlshen closed 2 years ago

mjlshen commented 2 years ago

The PagerDuty API is happy when only Type is set to omitempty, but I think it makes sense to do the same for AlertGroupParamsConfig as well as change it to be a pointer so that it gets a nil value instead of the zero value for all the config values in case the api checks those values in the future.

func main() {
    client := pagerduty.NewClient(authToken)
    svc, err := client.GetServiceWithContext(context.TODO(), serviceId, nil)
    if err != nil {
        panic(err)
    }

        // Whether there's no value from GetService or if it's set
    svc.AlertGroupingParameters.Type = ""

    _, err := client.UpdateServiceWithContext(context.TODO(), *svc)
    if err != nil {
                 // Results in panic: HTTP response failed with status code 400,
                 // message: Invalid Input Provided (code: 2001): Alert grouping parameters is invalid.
        panic(err)
    }
}

Fixes #438

mjlshen commented 2 years ago

@theckman @ChuckCrawford not sure if any of you have cycles to review this? Thanks!

ChuckCrawford commented 2 years ago

Thank you for your help with this @mjlshen .