grafana / grafana/alerting

Jira V2 contact point: search request sends 'expand' as empty string instead of omitting it

Open
#482 3 comments 4 reactions 1 assignee Claimed by @yuri-tceretian View on GitHub
Dominant language
Go
Stars
89
Forks
74
Avg merge
2d 7h
Merged PRs (30d)
8

Description

## Description

When using the Jira contact point with Jira Server/Data Center (REST API v2), the search for existing issues fails with a 400 error because the `expand` field in the `issueSearch` struct is serialized as an empty string (`"expand": ""`) instead of being omitted.

Jira Server v2 `/search` endpoint expects `expand` to be an array (`[]string`), not a string. Sending an empty string causes the following error:

```
failed to look up existing issues: HTTP request to JIRA API: webhook failed validation: unexpected status code 400:
{"errorMessages":["Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token
at [Source: ...; line: 1, column: 2]
(through reference chain: com.atlassian.jira.rest.v2.search.SearchRequestBean[\"expand\"])"]}
```

## Root Cause

In `receivers/jira/v1/types.go`, the `issueSearch` struct defines `Expand` as:

```go
type issueSearch struct {
Expand string `json:"expand"`
Fields []string `json:"fields"`
JQL string `json:"jql"`
MaxResults int `json:"maxResults"`
}
```

Since `Expand` is a `string` without `omitempty`, and `getSearchJql()` in `jira.go` never sets the `Expand` field, it serializes to `"expand": ""` in the JSON body. Jira Server's v2 API rejects this because it expects an array.

## Suggested Fix

Add `omitempty` to the JSON tag:

```go
Expand string `json:"expand,omitempty"`
```

Or change the type to `[]string` to match Jira's expected format:

```go
Expand []string `json:"expand,omitempty"`
```

## Related

- PR #415 fixed the v2 endpoint path (`/search` instead of `/search/jql`) but did not address the `expand` field serialization.
- Issue https://github.com/grafana/grafana/issues/112921

## Environment

- **Grafana**: Cloud Advanced v12.4.0
- **Jira**: Server/Data Center (self-hosted, REST API v2)

## Steps to Reproduce

1. Configure a Jira contact point in Grafana Alerting with a Jira Server v2 URL (e.g., `https://your-jira.com/rest/api/2`)
2. Fill in Project Key, Issue Type, and authentication
3. Click "Test" to send a test notification
4. The test fails with the deserialization error above

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.