Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

A javascript rest api example for adding a JIRA comment text with a png image or just a image file in comments

Neeraj Bodhe July 3, 2014

Can anyone provide me a code snippet example in js for a JIRA rest api to post a comment in a issue which includes a image as well a text or just a image.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Neeraj Bodhe July 8, 2014

Thanks Tiago,

I was trying this with respect to the onDemand plugin development instance. Below is the code snippet for nodejs

var httpClient = addon.httpClient({
                                    clientKey: req.session.clientKey,
                                    userKey: userkey,
                                    appKey: addon.key
                                });
                httpClient.post({
                    url: '/rest/api/2/issue/issue-key/comment',
                    headers: {
                        'X-Atlassian-Token': 'nocheck',
                        'Content-Type': 'application/json',
                        'Accept': 'application/json'
                    },
                    json: {
                        "body":"This is a my comment through rest api",
                    }
                    
                }, function(err, callbackRes, body) {
                     console.log( "body:" + JSON.stringify(body) + "   callbackRes : " + JSON.stringify(callbackRes));
                });

0 votes
Tiago Comasseto
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 3, 2014

Hi Neeraj,

The simplest way I can imagine adding a comment in a JIRA issue with a png image is with CURL as in the example bellow (reference):

ecrnt-06:~ tcomasseto$ set +H
ecrnt-06:~ tcomasseto$ 
ecrnt-06:~ tcomasseto$ curl -D- -u admin:sphere -X POST --data "{\"body\":\"!https://www.small-improvements.com/images/site/customers/testimonials/atlassian-logo.png!\"}" -H "Content-Type: application/json" http://ironman/jira625/rest/api/2/issue/TEST-1/comment
HTTP/1.1 201 Created
Date: Fri, 04 Jul 2014 16:15:05 GMT
Server: Apache-Coyote/1.1
X-AREQUESTID: 795x3376x1
X-ASEN: SEN-L3611469
X-Seraph-LoginReason: OK
X-ASESSIONID: 1fc0w8v
X-AUSERNAME: admin
Location: http://ironman/jira625/rest/api/2/issue/10202/comment/10413
Cache-Control: no-cache, no-store, no-transform
X-Content-Type-Options: nosniff
Content-Type: application/json;charset=UTF-8
Set-Cookie: JSESSIONID=9EC2DC819EB63F18BEEE47B3387A0306; Path=/jira625/; HttpOnly
Set-Cookie: atlassian.xsrf.token=B64A-MCV0-ICIO-W176|1ee7f8adbadd948316eb3558411bd694713aabd0|lin; Path=/jira625
Connection: close
Transfer-Encoding: chunked

{"self":"http://ironman/jira625/rest/api/2/issue/10202/comment/10413","id":"10413","author":{"self":"http://ironman/jira625/rest/api/2/user?username=admin","name":"admin","emailAddress":"admin@jiraadmin.jira","avatarUrls":{"16x16":"http://ironman/jira625/secure/useravatar?size=xsmall&avatarId=10122","24x24":"http://ironman/jira625/secure/useravatar?size=small&avatarId=10122","32x32":"http://ironman/jira625/secure/useravatar?size=medium&avatarId=10122","48x48":"http://ironman/jira625/secure/useravatar?avatarId=10122"},"displayName":"JIRA Administrator","active":true},"body":"!https://www.small-improvements.com/images/site/customers/testimonials/atlassian-logo.png!","updateAuthor":{"self":"http://ironman/jira625/rest/api/2/user?username=admin","name":"admin","emailAddress":"admin@jiraadmin.jira","avatarUrls":{"16x16":"http://ironman/jira625/secure/useravatar?size=xsmall&avatarId=10122","24x24":"http://ironman/jira625/secure/useravatar?size=small&avatarId=10122","32x32":"http://ironman/jira625/secure/useravatar?size=medium&avatarId=10122","48x48":"http://ironman/jira625/secure/useravatar?avatarId=10122"},"displayName":"JIRA Administrator","active":true},"created":"2014-07-04T13:15:06.761-0300","updated":"2014-07-04T13:15:06.761-0300"}

If the image is already attached to the JIRA issue, you can use just the markup !image.png!

I hope it helps.

Cheers

TAGS
AUG Leaders

Atlassian Community Events