Raise Comment On Behalf of Customer via API

Hi all,

Is there any way to raise a comment on behalf of a customer? Tried a bunch of stuff like adding author as per other posts, but no luck. It shows as posted by my connect add-on.

Further then, can we at least change the avatar of the connect add-on user via the API? I couldn’t find anything about that either.

Thanks!
Alex

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

@iragudo … you’re the best! :tada: Thank you! I was able to get it working with your code, and also had to convert it to a REST call outside of the add-on which this article I discovered helped with: User impersonation for Connect apps

Thanks for all the fast help!

Alex

1 Like