Raise Comment On Behalf of Customer via API

Hello @alexsopinka,

Yes you can, be sure that your app has ACT_AS_USER scope and the user you are impersonating has the necessary permission to comment on the ticket (or else you get a 403). I wrote a sample app using Atlassian Connect for Express and here’s the snippet to give you an idea.

app.get('/postOnBehalfOf', addon.authenticate(), function(req, res) {
//      var httpClient = addon.httpClient(req); // app generated user to post the comment
        var httpClient = addon.httpClient(req).asUserByAccountId(userAccountId); // impersonated user

        var bodyData = `{"body":"Hello there","public":true}`;
        
        
        httpClient.post({
            url: '/rest/servicedeskapi/request/TESTISSUE-1/comment',
            headers: {
                'X-Atlassian-Token': 'nocheck',
                'Content-Type': 'application/json'
            },
            body: bodyData
        },
        function (err, httpResponse, body) {
            if (err) {
                return console.error('Comment failed:', body);
            }
            console.log("http response: " + httpResponse.statusCode);
        });	    	     
});

Hope this helps.
Ian

2 Likes