Getting "401 Unauthorized" when trying to call rest API with JWT Token (Connect App)

I am getting “401 Unauthorized” when trying to make REST API Call with JWT Token which was generated using context exchange information during Connect App installation.

Here my code . I tried every possible way but still it seems like i’m missing something.

I am using “atlassian-jwt” package to generate token

function GetToken(){
const now = moment().utc();
const request = jwt.fromMethodAndUrl('GET', '/rest/api/3/issue');
    const tokenData = {
        "iss": 'com.example.myapp',
        "aud":"{clientKey}",
        "iat": now.unix(),       
        "exp": now.add(3, 'minutes').unix(),  
        "qsh": jwt.createQueryStringHash(request)
    };
    
    const secret = '{Shared_Secret_From_installation_context}';
    
    const token = jwt.encodeSymmetric(tokenData, secret);
    return token
}

Can you guys help me out where I’m doing wrong or missing something?

My Connect App Descriptor has Scope [“READ”,“WRITE”,“ACT_AS_USER”]

still no response i need someone helps on this?

Can you elaborate on when/how you are using the GetToken() method? What does res.send(token) do in this context?

Hi @remie
Thanks for your reply. I am calling this GetToken() method to get token for api /rest/api/3/issue for just to check if i’m able to make http call to jira rest api or not.
but i’m not able to do so.

and res.send(token) was a mistake it should be return token.
i have updated the post for the same.

1 Like