Forums

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

API Token for JIRA REST API not working

Greg Sternberg July 15, 2019

Earlier this month I converted from username/password to API token for my ruby script

options = {
:site => "<jira site>",
:context_path => "",
:auth_type => :basic,
"Authorization" => "Basic <base64 encoded email:apitoken>",
"Content-Type" => "application/json",
}
@@client = JIRA::Client.new option

However, my ruby script only gets an HTTPError and when I try curl:

curl -D- -u <base64 encoded email:apitoken> -X GET -H "Content-Type: application/
json" <jira web page>

It prompts me:

Enter host password for user '<base64 encoded email:apitoken>':

If i enter the password curl gives me the web page. So I have two questions: 1) Why is curl prompting me and 2) why doesn't the script connect as it's using the same things as the curl command?

1 answer

1 accepted

0 votes
Answer accepted
Thomas Deiler
Community Champion
July 15, 2019

Dear @Greg Sternberg ,

just to be sure - you are using Jira Server, correct? Then you can only OAuth or basic auth. Api Token is for cloud, only.

Or do you connect against Cloud?

So long

Thomas

Greg Sternberg July 15, 2019

It's the cloud (jira.com)

Thomas Deiler
Community Champion
July 15, 2019

Dear @Greg Sternberg ,

there is an article describing a solution for python. Hope you can translate this to Ruby.

So long

Thomas

Greg Sternberg July 16, 2019

Thomas,

   The python code put me on the right track as it worked so I knew it had something to to with the jira-ruby package. So between reading the source and some experimentation the answer was simple - don't base64 encode and don't build the authorization header - i.e. do:

options = {
:site => "<jira site>",
:context_path => "",
:auth_type => :basic,
:user => "<email>",
:password => "<apitoken>"
,
}
@client = JIRA::Client.new option

Thanks!

Like Robin Farkas likes this
Ian Russel Adem
Contributor
June 16, 2020

JIRA authentication so confusing.You must have a concise "rightway to do it" documentation.

Like Huda Rawasia likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events