The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Using personal access token to make REST APi call

Eunice
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 6, 2021

Hi,

We use Jira on-prem and I am attempting to automate the export of a saved search query to csv. I have tried both Power Query in Excel and PowerShell. 

I was initially successful when using Power Query to retrieve the information, with my username/password specified as part of the process. However, this has since stopped working (400 error) since I tried to replace my password with the personal access token. Now it won't work even if I revert back to using my username and password, after clearing the local/global cache and resetting captcha. (Totally regret trying to change something that was working fine!!!)

This led me to try automating the process fully in PowerShell via Basic authentication with a base64 encoded username and password. When captcha is triggered I get a 403 error as expected, but a 401 error when captcha is reset. Script is as follows (note: i haven't tried piping the output into a CSV yet and may try a direct 'export to CSV' link in place of the current URL):

$user = 'username'
$token = 'token'

$pair = "$($user):$($token)"

$encodedCred = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($pair))

$basicAuth = "Basic $encodedCred"

$Headers = @{
Authorization = $basicAuth
}
Invoke-WebRequest -Uri 'https://<base_url>/rest/api/2/search?jql= <saved filter>`
-Headers $Headers

Interestingly when I check the usage of my token via the Jira UI, there is no record of it being used under the "last authenticated" column. Is there anything else that needs to be enabled for this to work?

0 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.