How to add comments using rest api

ravi December 18, 2014

Hi All , 

I have been working and searching for an answer more than 2 weeks , can you anybody help me how to add comments in JIRA using rest api , i used post man client to make both PUT and POST and also curl but there is always an error and my comment is not added to that issue.

HTTP Method - POST

curl -D- -u r****t:p***L. -X POST --data {"body":"this is a comment."} -H "Content-Type: application/json" http://h**y.l***lak.com/rest/api/2/issue/IPS-183/comment 


HTTP Method - PUT

curl -D- -u r****t:p***L. -X PUT --data {"body":"this is a comment."} -H "Content-Type: application/json" http://h**y.l***lak.com/rest/api/2/issue/IPS-183/comment 


i tried to send the text and also attach file but i could not complete the request , i used -K for authentication on my mac as well for cUrl but of not use. please let me know as this a critical issue for my project .



8 answers

1 accepted

2 votes
Answer accepted
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 18, 2014

You don't need the -D parameter in your cURL command, and you also need to wrap your body string in single quotes.  This works for me:

curl -u admin:admin -X POST --data '{"body": "comment."}' -H "Content-type: application/json" http://localhost:2990/jira/rest/api/2/issue/TEST-1/comment
0 votes
ygor mendes April 3, 2019

function parse_jira_ids(){
for ID in "$(echo $log | grep -Po '(TEST-([0-9]{1,}))')"
do
echo $ID

echo "${ID}" > $fileName.txt (WORKING ) ->  Write "TEST-1" in fileName.txt


JIRA_URL_1="https://jira.linx.com.br/rest/api/2/issue/TEST-1/comment"

JIRA_URL_2="https://jira.linx.com.br/rest/api/2/issue/$ID/comment" (NOT WORKING)

curl -k -u 'user':'pass' -X POST --data '{"body": "exemple" }' -H "Content-type: application/json" $JIRA_URL_1 >> aapost-commit.log 2>&1 (working )

curl -k -u 'user':'pass' -X POST --data '{"body": "$ID" }' -H "Content-type: application/json" $JIRA_URL_2 >> aapost-commit.log 2>&1 (NOT working )
done
}

 

I am not do POST when i try send a variable. Some know why????

0 votes
kiran kumar October 15, 2018

# Example property file for Clone Plus
# More details are available in the documentation: https://bobswift.atlassian.net/wiki/display/JCPP/Clone+properties


# Show this action for all projects, issue types and status
1.condition.TKM.*.* = true

# Restrict clone operation to support and administrators
1.role.* = Support, Administrators

# Names that show to users
1.label = Escalate to Engineering
1.tooltip = Creates a task for Engineering

#Clone Options Hide
1.option.copyAttachments = hide
1.option.copyWatchers = true
1.option.copyComments = true
1.option.copySubtasks = hide
1.option.copySubtaskEstimates = hide
1.option.copyParentVersions = hide
1.option.copyLinks = hide



# Show this action for all issues of type bug (id = 1) or task (3)
1.plus.condition.*.1.* = true
1.plus.condition.*.3.* = true

# Restrict clone operation so administrators
1.plus.role.* = Administrators

# Names that show to users
1.plus.label = Clone for administrators
1.plus.tooltip = Custom clone action

# Map issue type to default to a task (id = 3)
1.plus.type.*.*.* = 3

# Set fields
1.plus.set.summary = Clone of issue with summary: %original_summary%
1.plus.fieldExcludes = priority, Sprint, description, reporter

#Custom Clone+ that clears the Sprint field
 
  1.label = Clone+ 1
  1.tooltip = Clone within the same project and issue type
  1.fieldExcludes = priority, Sprint, description, reporter

#Custom Clone++ that clears the Sprint field
  1.plus.condition.*.*.* = true
  1.plus.label = Clone++ 1
  1.plus.tooltip = Clone to a different project
  1.plus.fieldExcludes = Sprint


#Custom Clone++ that Excludes the Sprint field using the field label
  2.plus.condition.*.*.* = true
  2.plus.label = Clone++ 2
  2.plus.tooltip = Clone to a different project
  2.plus.fieldExcludes = Sprint

0 votes
kiran kumar October 15, 2018

# This file needs to be put in the user configured jira home directory
# Property values can be referenced by key in other property values using ${key} syntax

# mappings keys are dot separated property names
# 1. prefix - start with the profilePrefix or blank (default prefix)
# 2. class - determines what mapping is being defined - like project, type, etc...
# 3. qualifier(s)
#    - one or more (dot separated) qualifiers - the number of qualifiers is dependent on the class
#    - generic qualifier (*) matches any value of that position, lookup by most specific first
# Example: 1.project.JRA.1.* will match an issue in the JRA project with has type bug (1) in any (*) status
# See below for examples
# Note that blanks in property keys must be escaped (with a \).

# class = project - map to a new project (key or id) based on project (key or id), issue type (id) and status (id)
# class = project-component - map to a new project (key or id) based on project (key or id) and component (name or id)
# class = type - map to a new type (id) based on project (key or id), issue type (id) and status (id)
# class = component - map a component (name) to a new component (name)
# class = version - map a version (name) to a new version (name)
# class = condition - profile condition to determine if web action shows for a specific issue - shows if matches and value is not false
# - based on project (key or id), issue type (id) and status (id)
# - used in conjunction with MatchPropertyCondition
# class = role - role restriction for operation by specific project (key or id)

# standard type ids
# - bug (1)
# - new feature (2)
# - task (3)
# - improvement (4)
# - subtask (5)

# standard status ids
# - open (1)
# - in progress (3)
# - re-opened (4)
# - resolved (5)
# - closed (6)

# standard priorities
# - blocker (1)
# - critical (2)
# - major (3)
# - minor (4)
# - trivial (5)

# Variable replacements are available using @...@ syntax for the following:
# original issue values: issuekey, summary, description, reporter, assignee, labels, security
# cloned issue - parent of cloned subtasks: parent.issuekey, parent.summary, parent.description, parent.reporter, parent.assignee, parent.labels, parent.security

# Custom fields not to copy to cloned issue. Default is no fields excluded.
# This is a comma separated list of exact field names or field id (like customfield_10100).
# Double quote names containing a comma.

 

 

 

# Example property file for Clone Plus
# More details are available in the documentation: https://bobswift.atlassian.net/wiki/display/JCPP/Clone+properties


# Show this action for all projects, issue types and status
1.condition.*.*.* = true

# Restrict clone operation to support and administrators
1.role.* = Support, Administrators

# Names that show to users
1.label = Escalate to Engineering
1.tooltip = Creates a task for Engineering

#Clone Options Hide
1.option.copyAttachments = hide
1.option.copyWatchers = true
1.option.copyComments = true
1.option.copySubtasks = hide
1.option.copySubtaskEstimates = hide
1.option.copyParentVersions = hide
1.option.copyLinks = hide



# Show this action for all issues of type bug (id = 1) or task (3)
1.plus.condition.*.1.* = true
1.plus.condition.*.3.* = true

# Restrict clone operation so administrators
1.plus.role.* = Administrators

# Names that show to users
1.plus.label = Clone for administrators
1.plus.tooltip = Custom clone action

# Map issue type to default to a task (id = 3)
1.plus.type.*.*.* = 3

# Set fields
1.plus.set.summary = Clone of issue with summary: %original_summary%
1.plus.fieldExcludes = priority, sprint, description, reporter


#Custom Clone+ that clears the Sprint field
  1.condition.*.*.* = true
  1.label = Clone+ 1
  1.tooltip = Clone within the same project and issue type
  1.set.customfield_11632=

#Custom Clone++ that clears the Sprint field
  1.plus.condition.*.*.* = true
  1.plus.label = Clone++ 1
  1.plus.tooltip = Clone to a different project
  1.plus.set.customfield_11632=

#Custom Clone+ that Excludes the Sprint field using the field label
  2.condition.*.*.* = true
  2.label = Clone+ 2
  2.tooltip = Clone within the same project and issue type
  2.fieldExcludes = priority

#Custom Clone++ that Excludes the Sprint field using the field label
  2.plus.condition.*.*.* = true
  2.plus.label = Clone++ 2
  2.plus.tooltip = Clone to a different project
  2.plus.fieldExcludes = priority

0 votes
arun tejaswi akella June 29, 2015

i am trying to add a comment to an issue same way as above. but i'm not able to add a comment. please someone guide me how to add a comment

Kyle
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.
July 18, 2017

Based on the accepted answer above, the sample curl code only work for me in Windows is when i escaped the quotes in of the body.

In Windows, do this:

curl -u admin:admin -X POST --data "{\"body\": \"comment.\"}" -H "Content-type: application/json" http://localhost:2990/jira/rest/api/2/issue/TEST-1/comment

Single quote or double quote to wrap the --data works either way.

Kyle
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.
July 18, 2017

The documentation needs an update to include the escaped quotes in the curl data.

Kishen June 4, 2018

@Kyle How would you automate this. For example, to post a comment I am using the same format as "{\"body\": \"comment.\"}". How do I pass a method which generates a comment based on the data input from the application. Is there a way where I can pass for example GenerateComment() instead of comment in the text above ?

 

Appreciate your time.

Kishen

0 votes
ravi December 18, 2014

Hi Joseph , 

Did exactly the same what you mentioned but do we need to use HTTPS or HTTP i tried using both of them but it is not adding a comment and it printsout - 

curl -k -u admin:admin -X POST --data '{"body":"this is a comment."}' -H "Content-Type: application/json" https://hxyp.dev.com:8443/rest/api/2/issue/FACI-323/comment 

{"errorMessages":["You do not have the permission to see the specified issue."],"errors":{}}itlogins-mbp-2:curl-7.39.0

i also downloaded the cUrl client for mac and gave my super user password too but still i am passing -k for authentication with my cUrl command but it says you dont have permission and also i have my rest api turned on my JIRA server instance for allowing remote api calls . 

 what do i need to do on the server side for this issue regarding the permission request and also can you send me a screenshot in postman client that will be really helpful . 

 

Thanks
 

 

 

Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 18, 2014

You need to replace "admin:admin" with your own username and password :)

Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 18, 2014

The permission error most likely means that your request is not logging in properly - there shouldn't need to be any server changes that you need to make.

Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 18, 2014
ravi December 18, 2014

Thank you very much Joesph , the screen shot you shared with me helped me a lot .

Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 19, 2014

Great! I'm glad it helped :)

ravi December 20, 2014

Hi James , Thanks and i have a question , can you please let me know which api do we need to use in order to get the activity streams for the projects . Thanks Very much !

Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 22, 2014

The documentation is here: https://developer.atlassian.com/display/DOCS/Consuming+an+Activity+Streams+Feed The URL is "/activity" and the response body is an XML document that you will need to parse.

0 votes
ravi December 18, 2014
  • Screen Shot 2014-12-18 at 10.15.13 AM.png

 

Hi thanks for your quick response , can you please see the above , i know it says invalid media type , i tried different methods of attaching pictures as well but it is not letting me do it .

0 votes
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 18, 2014

What kind of error do you get?  Can you show us the HTTP response code and the response body and headers that you receive when you try to run this command?

 

Suggest an answer

Log in or Sign up to answer