currentUser() function not working on search Rest call jql

209 views
Skip to first unread message

Álvaro Aranda (Deiser)

unread,
Jul 13, 2016, 3:08:05 AM7/13/16
to Atlassian Connect Dev
Hi everyone,

We are developing some JIRA Cloud addons and we have a problem while calling the search REST (/rest/api/2/search) to look for some issues with the currentUser() function in the jql we passed to it as a parameter.

The problem is that if we use this REST call externally, using Curl or whatever, we are returned some issues as data(we tried with the basic auth header with the same user that is working in JIRA with the addon). But, if we do the REST call from inside the addon, although the same user is provoking the REST call, we have no data returned back.

This is the code we use to make the REST call (admin is the user who is using JIRA with our addon, so it should be the currentUser. Moreover, admin is the user used on the basic auth of the external REST call):

addon.httpClient({
    clientKey
: theClientKey,
    userKey
: admin,
    appKey
: theAppKey
}).get(
   
{
        url
: '/rest/api/2/search?&jql=assignee=' + currentUser()
   
},
   
function (err, httpResponse, body) {
   
//httpResponse.statusCode was 200
   
//JSON.parse(body) was { startAt: 0, maxResults: 100, total: 0, issues: [] }
   
}
);


Why is currentUser() function working in a different way for that situations?

Thanks!

Fernando Boucquez

unread,
Jul 13, 2016, 9:43:36 AM7/13/16
to atlassian-...@googlegroups.com
Hi Alvaro, 

if you are calling from your UI Iframe to the client host, you should use the js bridge. For remote calls, use RA.request method:


RA.request({
    url: '/rest/api/2/search?&jql=assignee=' + currentUser,
    success: function (
response, message, xhr) {
        response = JSON.parse(response);
    },
    error: function (xhr) {
        
    }
});

https://developer.atlassian.com/static/connect/docs/latest/guides/connect-cookbook.html

https://developer.atlassian.com/static/connect/docs/latest/concepts/connect-cookbook-jira.html

Not sure where currentUser() is defined, I know you can use the bridge also to get the current logged user

AP.getUser(function (user) {

});

These objects are provided when you include the bridge js (all.js or all-debug.js) that you can include from the JIRA host

<script src="https://theclienthost.atlassian.net/atlassian-connect/all.js" type="text/javascript" data-options="sizeToParent:false"></script>

JIRA also provides the current user when loading the iframe in the user_key query parameter.

--
You received this message because you are subscribed to the Google Groups "Atlassian Connect Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to atlassian-connec...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Wester

unread,
Jul 13, 2016, 1:59:28 PM7/13/16
to Atlassian Connect Dev
You're executing the query as the add-on user so that's what it's returning. The request to your add-on will have the username/key (if known) in the query string so you can just use that instead of currentUser(). Note though that Issue Security/Permissions will be apply to the search results so you may not see all issues. If you're wanting all of the issues, your best bet is to do what Fernando described.
Reply all
Reply to author
Forward
0 new messages