Can't make REST calls to Jira using Atlassian Connect Express

I’m trying to access a user’s displayName using the endpoint which according to the docs requires only the READ scope, which appears in my descriptor.

Here’s my route:

app.get('/test', addon.checkValidToken(), function(req, res){
        console.log("test called");
        var httpClient = addon.httpClient(req);
        httpClient.get('/rest/api/latest/user?key=admin', function(err, response, body) {
            console.log(body);
        })
    });

I know it’s getting a valid call from the iFrame because I can see “test called” in the logs, but then I get Encountered a “401 - Unauthorized” error while loading this page. as the body. I also know the endpoint is correct because visiting that URL in the browser returns valid JSON.

Any way of understanding what might be going wrong? Are the docs wrong and I need an admin scope?

Have you tried with /rest/api/2/user instead of /rest/api/latest/user ?

Hello @wsdan,

I’ve tried your sample and I was able to get a positive response (which means we’re good with the scope and endpoint). The error you got, 401, usually happens when addon is not authenticated. Kindly check this Atlassian Connect Jira example for reference, specifically routes/index.js.

Cheers,
Ian

After digging around, I found the problem being that the addon key was different when ENV=production and ENV=debug.

Looks like I was the killer, kids, let this be a lesson that messing with the add-on key will allow all of your inbound requests to authenticate if they were registered against the original key, but break all outbound requests.

Thanks for checking I wasn’t going crazy.

3 Likes

That’s a really good lesson to learn. Thanks for sharing!