Jira Personal Access Token in Jira Cloud
I am trying to create some basic automation to be used with personal access tokens. For the begining I want to fetch an issue by ID.
When I have a token created with “Create API token without scopes” and use it with basic auth it works just fine:
curl -D- -u myusername@mycompany.com:MY_TOKEN_WITHOUT_SCOPE -X GET -H "Content-Type: application/json" https://mycompany.atlassian.net/rest/api/3/issue/UU-42
Equivalent in javascript:
// Construct the full API URL
const apiUrl = `https://${mycompany}.atlassian.net/rest/api/3/issue/${jiraKey}`;
// Encode credentials for Basic Authentication header
const credentials = `${username}:${token}`;
const encodedCredentials = Buffer.from(credentials).toString('base64');
const authHeader = `Basic ${encodedCredentials}`;
// Define request headers
const headers = {
'Authorization': authHeader,
'Accept': 'application/json', // Tell the server we expect JSON back
// 'Content-Type': 'application/json' // Usually not needed for GET requests
};
display(`Fetching Jira issue: ${apiUrl}`);
const response = await fetch(apiUrl, {
method: 'GET',
headers: headers,
});
Using it with Bearer
does not work.
However, if I create a token with “Create API token with scopes” nothing seems to work.
curl -D- -H "Authorization: Bearer MYTOKENWITHSCOPE" -X GET -H "Content-Type: application/json" https://mycompany.atlassian.net/rest/api/3/issue/UU-42
Equivalent in javascript:
// Construct the full API URL
const apiUrl = `https://${mycompany}.atlassian.net/rest/api/3/issue/${jiraKey}`;
const authHeader = `Bearer ${myTokenWithScope}`;
// Define request headers
const headers = {
'Authorization': authHeader,
'Accept': 'application/json', // Tell the server we expect JSON back
// 'Content-Type': 'application/json' // Usually not needed for GET requests
};
display(`Fetching Jira issue: ${apiUrl}`);
const response = await fetch(apiUrl, {
method: 'GET',
headers: headers,
});
It responds 403 {"error": "Failed to parse Connect Session Auth Token"}
Attempt to use PAT with scope the old way is a bit fruitless:
curl -D- -u myusername@mycompany.com:MY_TOKEN_WITH_SCOPE -X GET -H "Content-Type: application/json" https://mycompany.atlassian.net/rest/api/3/issue/UU-42
Responds 404 {“errorMessages”:[“Issue does not exist or you do not have permission to see it.”],“errors”:{}}
I first tried setting up Granular read:issue:jira
I thought I maybe didn’t add enough so I added quite a lot: read:issue:jira
read:field:jira, read:issue-meta:jira, read:issue-field-values:jira, read:user.columns:jira, read:comment.property:jira, read:jql:jira, read:screen-field:jira, read:issue-link:jira, read:jira-expressions:jira, read:issue:jira-software, read:issue-type-transition:jira, read:issue-type:jira, read:project.feature:jira, read:label:jira, read:board-scope:jira-software, read:issue-event:jira, read:issue-details:jira, read:priority:jira, read:issue.transition:jira, read:epic:jira-software, read:issue-type.property:jira, read:design:jira, read:screen:jira, read:issue.remote-link:jira, read:customer.detail-field:jira-service-management, read:dashboard:jira, read:sprint:jira-software, read:project:jira, read:project-type:jira, read:issue.property:jira and it didn’t help either.
I thought this may be an issue with granular scope, so I tried setting all classic scopes read:jira-work
and so on and it didn’t help as well.
Then I tried setting up all possible granular scopes and nothing seems to work.
Please help with a working out example to do basic issue read with scoped PAT.