如何进行 Jira REST API 调用来获取特定值?

问题描述 投票:0回答:1

我正在使用此示例 url 进行 Jira REST API 调用:

http://example.com/rest/api/2/search/?jql=project=example%20and%20type=test&fields=customfield_14600

这是返回的 JSON 的示例

{
    "expand":"names",
    "startAt":0,
    "maxResults":50,
    "total":2,
    "issues":[
        {
            "expand":"examples",
            "id":"1111",
            "self":"https://example.com/rest/api/2/issue/111111",
            "key":"EX-1111",
            "fields":{
                "customfield_14600":{
                    "self":"https://example.com/rest/api/2/customFieldOption/1111",
                    "value":"Common",
                    "id":"11111",
                    "disabled":false
                }
            }
        },
        {
            "expand":"examples",
            "id":"1111",
            "self":"https://example.com/rest/api/2/issue/111111",
            "key":"EX-1111",
            "fields":{
                "customfield_14600":{
                    "self":"https://example.com/rest/api/2/customFieldOption/1111",
                    "value":"Uncommon",
                    "id":"11111",
                    "disabled":false
                }
            }
        }
    ]
}

Here is an image of the returned JSON with better formatting

我将使用什么 URL 来仅返回 customfield_14600 值为“Common”的问题?基本上我试图返回具有“Common”值的问题数量。

谢谢你。

api rest jira jira-rest-api jira-rest-java-api
1个回答
0
投票

由于您使用的是 JQL 查询,因此您可以添加另一个过滤器来检查您需要的自定义字段是否具有您需要的值,如下所示:

project = example AND type = test AND cf[14600] = "Common"

或者,如果您知道自定义字段的名称和/或希望它易于阅读:

project = example AND type = test AND "Field name" = "Common"

您可以查看手册了解更多运算符/关键字。

在另一个主题上,我建议使用

POST
端点而不是
GET
端点来进行包含复杂查询的搜索。查看REST API 文档以获取说明。

© www.soinside.com 2019 - 2024. All rights reserved.