Get all issue for jira

Mertcan Karabaş May 10, 2024

Hello, I want to bring all issues in Jira or certain issues with JQL through my application. I can get a single issue by sending a request as /rest/api/3/issue/T1-1. However, when I request /rest/api/3/search?jql=..., I get the error {“code”:401,“message”:“Unauthorized; scope does not match”}.

Here is my code below:

try {
    if (issueIdOrKey === undefined || issueIdOrKey === null) {
        response = await api.asUser().requestJira(route`/rest/api/3/search?`, {
            headers: {
                 'Accept': 'application/json'
             }
       });
    } else {
         response = await api.asUser().requestJira(route`/rest/api/3/issue/${issueIdOrKey}`, {
            headers: {
                  'Accept': 'application/json'
             }
        });
    }
    console.log(`Response: ${response.status} ${response.statusText}`);
    return await response.json()
} catch (error) {
console.error('Error:', error);
throw error;
}

Here is my permissions below:
permissions:
    scopes:
    - 'read:jira-work'
    - 'read:issue-meta:jira'
    - 'read:issue-security-level:jira'
    - 'read:issue.vote:jira'
    - 'read:issue.changelog:jira'
    - 'read:avatar:jira'
    - 'read:issue:jira'
    - 'read:status:jira'
    - 'read:user:jira'
    - 'read:field-configuration:jira'

1 answer

1 vote
Vijay Dadi
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 10, 2024

Hi @Mertcan Karabaş ,

You have to use base64 encoded api token.

Mertcan Karabaş May 10, 2024

Hi @Vijay Dadi 
Where do in the code should I add the base64 api token? and how can i get this token? If I need to create and use 'https://id.atlassian.com/manage-profile/security/api-tokens' from here, how can I request this from users?

Vijay Dadi
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 10, 2024

The api token has to be generated for your service account one time and can be re-used. Once you encode it for base 64, use it in your header as

'Authorization': 'Basic <base64 encoded api token>'

Mertcan Karabaş May 10, 2024

I'm using macOS and I created the base64 token in the terminal like this:
echo -n my_mail@gmail.com:my_api_token | base64

headers: {
'Accept': 'application/json',
'Authorization': 'Basic a2FyYWJh...'
}


then i added to my header but i got same error. Could there be another problem?

Mertcan Karabaş May 10, 2024

Hi, @Vijay Dadi 

I solved the problem and the reason was from a different part of the code. I was checking whether the input I received was undefined or null and that's why it was entering the second if block. Therefore, since the request was sent as rest/api/3/issue/, it gave an error. Again, thank you very much for your help.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events