You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过JIRA REST API获取问题的描述及经办人姓名?

Fetch Jira Issue Description & Assignee Name via Java REST API

Got it, let's break this down! Since you're already pulling issue keys using the Jira REST API in Java, expanding that to grab descriptions and assignee names is totally doable—either by adjusting your initial query to include those fields upfront, or by making targeted follow-up requests for each issue key you already have.

Instead of fetching just keys first, modify your search request to include the description and assignee fields directly. This saves you from making extra API calls for each issue, which is way more efficient.

If you're using Atlassian's official jira-rest-java-client-core (the most common library for this workflow), here's a hands-on code snippet:

First, add the Maven dependency (if you haven't already):

<dependency>
    <groupId>com.atlassian.jira</groupId>
    <artifactId>jira-rest-java-client-core</artifactId>
    <version>5.2.0</version> <!-- Use the latest version compatible with your Jira instance -->
</dependency>

Then, adjust your search code to pull in the required fields:

import com.atlassian.jira.rest.client.api.JiraRestClient;
import com.atlassian.jira.rest.client.api.domain.Issue;
import com.atlassian.jira.rest.client.api.domain.SearchResult;
import com.atlassian.jira.rest.client.auth.BasicHttpAuthenticationHandler;
import com.atlassian.util.concurrent.Promise;

import java.net.URI;

public class JiraIssueDetailsFetcher {
    public static void main(String[] args) {
        // Initialize Jira REST Client with your credentials
        URI jiraServerUri = URI.create("https://your-jira-instance-url.com");
        JiraRestClient restClient = com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory
                .newInstance()
                .create(jiraServerUri, new BasicHttpAuthenticationHandler("your-username", "your-api-token"));

        try {
            // Define your JQL query and specify the fields we need
            String jqlQuery = "project = YOUR_PROJ_KEY AND status != Closed"; // Replace with your actual JQL
            Promise<SearchResult> searchPromise = restClient.getSearchClient()
                    .searchJql(jqlQuery, 50, 0, "key,description,assignee");

            SearchResult result = searchPromise.claim();
            for (Issue issue : result.getIssues()) {
                // Extract issue key (you already know this part)
                String issueKey = issue.getKey();
                
                // Extract description (handle cases where no description exists)
                String description = issue.getDescription() != null ? issue.getDescription() : "No description provided";
                
                // Extract assignee name (handle unassigned issues)
                String assigneeName = issue.getAssignee() != null ? issue.getAssignee().getDisplayName() : "Unassigned";

                // Print or process the data as needed
                System.out.println("Issue Key: " + issueKey);
                System.out.println("Description: " + description);
                System.out.println("Assignee: " + assigneeName);
                System.out.println("------------------------");
            }
        } finally {
            restClient.close();
        }
    }
}

Option 2: Fetch Details for Existing Issue Keys

If you already have a list of issue keys and need to retrieve their details one by one, use the getIssueClient().getIssue(issueKey) method:

// Assume you have a pre-existing list of issue keys
List<String> issueKeys = List.of("PROJ-123", "PROJ-456", "PROJ-789");

for (String key : issueKeys) {
    Promise<Issue> issuePromise = restClient.getIssueClient().getIssue(key);
    Issue issue = issuePromise.claim();
    
    // Extract fields the same way as before
    String description = issue.getDescription() != null ? issue.getDescription() : "No description provided";
    String assigneeName = issue.getAssignee() != null ? issue.getAssignee().getDisplayName() : "Unassigned";

    System.out.println("Key: " + key + " | Assignee: " + assigneeName + " | Description: " + description);
}

Quick Tips

  • Null Safety: Always check if description or assignee is null—many issues don't have descriptions or are unassigned, so this prevents runtime errors.
  • Permissions: Make sure your Jira user (or API token) has permission to view the target issues and their fields.
  • Pagination: If you're fetching a large number of issues, use the startAt and maxResults parameters in your JQL search to avoid hitting API rate limits.

内容的提问来源于stack exchange,提问作者GUMMADI VIJAYA KUMAR

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 06:54:30