Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Create internal comment with jira java rest client?

Peter H May 23, 2018

Hi,

is it possible to create an internal comment for an issue with the java rest client? When i create it with just the comment text itself, the comment is public and visible for customers in the service desk. In the JIRA Gui there is the button "Comment internally" for that.

This is how i currently create an comment:

jiraRestClient.getIssueClient().addComment( issue.getCommentsUri(), Comment.valueOf( "My comment" ) ).claim();

 

Thanks in advance!

2 answers

0 votes
Hubbitus
Contributor
November 6, 2023
import com.atlassian.jira.rest.client.api.IssueRestClient;
import com.atlassian.jira.rest.client.api.JiraRestClient;
import com.atlassian.jira.rest.client.api.SearchRestClient;
import com.atlassian.jira.rest.client.api.domain.Comment;
import com.atlassian.jira.rest.client.api.domain.SearchResult;
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory;

import java.net.URI;
import java.net.URISyntaxException;

class Scratch {
public static void main(String[] args) throws URISyntaxException {
try(JiraRestClient jiraRestClient = new AsynchronousJiraRestClientFactory()
.createWithBasicHttpAuthentication(new URI("https://jira.example.com"), "username", "password")) {
SearchRestClient searchClient = jiraRestClient.getSearchClient();
IssueRestClient issueClient = jiraRestClient.getIssueClient();
String jql = "project = DATA ...";
SearchResult searchResult = searchClient.searchJql(jql).claim();
searchResult.getIssues().forEach(issue -> issueClient.addComment(issue.getCommentsUri(), Comment.valueOf("My comment")));
}
catch (Exception e){
System.out.println("Exception handling...");
}
}
}
0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 23, 2018
Peter H May 23, 2018

This does not help me because i'm using the java rest client and also jira on premise instead of jira cloud.

In the java rest client i have not the possibility to set properties for an comment...

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 23, 2018

Try to use PUT /rest/api/2/comment/{commentId}/properties/{propertyKey}

I am not sure which java rest client you use. But you can always use the jersey client.

Peter H May 23, 2018

I am using this library: https://marketplace.atlassian.com/apps/39474/rest-java-client-for-jira?hosting=server&tab=overview

The requests are builded by the library, so i cant modify them. 

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 23, 2018

I think if a framework does not let you do something, then you either have to ask the developers of the framework, how to do it, or find another framework. 

Suggest an answer

Log in or Sign up to answer