accessing jira via api

Yas Saghiri July 26, 2022

Hello all:

I am trying to access Jira via the APIs. When logged into Jira, if I run an API request in a browser it works fine (but that is because I am already authenticated). However, when I attempt to run the same query either using a test app I created in C# or Postman I get a response back saying "Unauthorized (401)".

I created an API token and I also created a personal token. I tried both to authenticate but no luck.

Here is the cURL command I am using:

curl -D- \
-X GET \
-H "Authorization: Basic base64 user name and api token here" \
-H "Content-Type: application/json" \
https://my jira server/rest/api/2/search?jql=jql query

 

What am I doing wrong?

Thanks in advance.

 

Regards

 

Yas

1 answer

0 votes
Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 26, 2022

Hi @Yas Saghiri 

I've tried you http request and I have no problem getting a response. I used basic authentication and I entered my username and password. Postman agent automatically turned this to base64 encoding.

I would suggest that you double check your username and password. The first time, and because I am used to, I entered my email address as the username and I was getting 401. :)

Hope that helps.

Alex

Yas Saghiri July 26, 2022

Unfortunately it is not working for me. I did as you suggested and checked, and re-checked, my user name and password, and my credentials allowed me to access Jira going directly (ie: not through the API). I used my username and my email address and still the same.

I checked my access rights to the project I am querying through the API and I have access, I can use jql, and I can add, change, read and delete issues. In fact I have admin rights to the project where I can even create and make changes to workflows, screen schemas, the whole shebang.

If I had any hair I would have pulled it out by now.

I want to cry.

Is there anything else I can look at or try.

 

Regards

 

Yas

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 26, 2022

Can you try another request, like read an issue from any other project?

Yas Saghiri July 26, 2022

I will give that a try. I will also get another user created with the same access rights and try that in case my profile is corrupt in some way.

Thanks for your help so far. I will let you know what happens.

Regards

Yas

Yas Saghiri July 26, 2022

 Tried alternative requests (requested a single issue, single project without jql in the api call), but I got the same result. I  have had a look at my profile under the user management tab and strangely each time is send an api request the number of failed goes up by 2 which I don't understand. Any ideas why that should happen?

Regards

Yas

Yas Saghiri August 2, 2022

@Alex Koxaras _Relational_ 

My apologies for linking you in, but you seem the only person who is responding. I am pulling my hair out here. I cannot make this API call work. I have done all of the above. Further more, I have even gone to the trouble of creating a whole new project with me as the owner, lead, admin. In terms of control of this new project, there is me and then there's God (apologies if that offends any religious beliefs you might have, but I am using it for emphasis). Still the same problem "Unauthorized (401)".

I have spoken with a few people about this (both inside and outside my organisation) and I am going to try one more thing to see if I can resolve it before I go cap in hand to request some form of consultancy from Atlassian to help resolve this.

My current user (ie: me) authenticates via Active Directories and I am thinking (and this is just guessing because I cannot find any documentation on this) that making an API request is in some way making the same authentication and failing. As I said in one of my previous comments above, each time I make a failed call Jira registers 2 failed attempts. To validate this (perhaps) and to try some out of the box thinking, I have requested that a user is created in Jira directly rather than be pulled from AD and see if I can authenticate using that.

This will take a while because we are in the middle of an office move and the team that can help are busy working on that, however, while that is being done any help, advice or out of the box thinking you could suggest would be very, very, very much appreciated.

Regards

Yas

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 16, 2022

@Yas Saghiri hi!

Sorry for the late reply, but vacation happened :)

Can you please share any screenshot of your project URL, the API Request and whatever else useful? We might be able to find the problem there.

Suggest an answer

Log in or Sign up to answer