getting 401 Unauthorized even with user name and PAT

Uncleweb February 1, 2024

Tried connecting jira using api with username and profiletoken in password but it returns 401-unauthorized

we connect web ui using sso

2 answers

1 vote
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 1, 2024

Hi @Uncleweb 

I think there is some confusion over the terms used here.  Personal Access Tokens (PATs) are only used within our Server and Data Center products as explained in Using Personal Access Tokens.

If you happen to be using an Atlassian Cloud site, those instructions should be disregarded.  Instead for Atlassian Cloud please see Manage API tokens for your Atlassian account to understand how to create an API token your Atlassian Account can use for our Cloud services.  Also the steps in Basic auth for REST APIs are useful for learning the expected means of supplying this token within a header.

Uncleweb February 1, 2024

@Andy Heinzer thanks for pointing out and I can confirm that this 401 authorized on data center product

Uncleweb February 2, 2024

@Andy Heinzer After changing "Type" from basic to bearer now I can get 200 OK but in response getting whole html page source code which cantans lot of hyper links along with login page asking username and password.

Any hints?

 

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 2, 2024

What endpoint are you calling in your REST request?  Perhaps it might help to see the command you are trying to run.  But I would recommend that you not post your actual PAT or your actual URL here in Community, as this is a public site.

Uncleweb February 4, 2024

HI @Andy Heinzer

Here are the details I am using in order to connect 

endpoint: https://jira.abc.mycompanydomain.com/rest/api/3/issue

Headers: Content-Type / application/json

body of request

{
    "fields": {
       "project":
       {
          "key""Ting"
       },
       "summary""Jira ticket using API.",
       "description": {
          "type""doc",
          "version"1,
          "content": [
            {
              "type""paragraph",
              "content": [
                {
                  "type""text",
                  "text""description"
                }
              ]
            }
          ]
        },
       "issuetype": {
          "name""Story"
       }
   }
}
apiresult.JPG
Uncleweb February 5, 2024

I am using Bearer token with my PAT in Authentication though we always connect web page using SSO

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 5, 2024

Based on the response of the login page, it looks like your authorization is failing. The payload looks like you're trying to do a POST to that endpoint.   While you can start there, I tend to suggest trying to do a GET from that endpoint of a known existing issue that your account has access to.  This tends to be a bit easier to make sure that you can get back the expected output before trying to create a new issue.

I recommend trying to follow the steps in https://developer.atlassian.com/server/jira/platform/basic-authentication/ to encode your credentials in the base64 string and then pass that encoded string as part of an authorization header.  If this is done correctly, you should get back the issue details in a json format.

 

Uncleweb February 5, 2024

Thanks @Andy Heinzer

I have check with get and its working and I could see the ticket detail in response

0 votes
Nikola Perisic
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 1, 2024

Welcome to the community @Uncleweb !

Which app you are using? Postman? Are you also using a programming language to fetch data?

Make sure that for your username you use your email and for the password that you are using the Jira API token.

Uncleweb February 1, 2024

@Nikola Perisic I am using postman and I am using my mail id and Jira api token

do you think it could be that some restriction at jira is not letting me call api?

Nikola Perisic
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 1, 2024

@Uncleweb 

I am using Postman as well, and for authorization I am using the Basic Auth. Are you using the same auth type?

Uncleweb February 1, 2024

yes

Uncleweb February 1, 2024

I have tried it with my test account and it works but not for my work jira hence curious if there are config which let us block users to connect using api

Nikola Perisic
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 1, 2024

Understood. I have the rate limiting for API, but this is more blocking the users to use the API at all. I would see what others from community think about this.

Nikola Perisic
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 1, 2024

I added additional tags for wider visibility.

Like Uncleweb likes this
Uncleweb February 2, 2024

Thanks @Nikola Perisic 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events