getting 401 Unauthorized even with user name and PAT
Asked by Uncleweb:

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

we connect web ui using sso


Answers:
author: Andy Heinzer
body: Hi [@Uncleweb](/t5/user/viewprofilepage/user-id/5420093)

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](https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html).

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](https://support.atlassian.com/atlassian-account/docs/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](https://developer.atlassian.com/cloud/jira/platform/basic-auth-for-rest-apis/) are useful for learning the expected means of supplying this token within a header.

comments: author: Uncleweb
body: [@Andy Heinzer](/t5/user/viewprofilepage/user-id/541137) thanks for pointing out and I can confirm that this 401 authorized on data center product


author: Uncleweb
body: [@Andy Heinzer](/t5/user/viewprofilepage/user-id/541137) 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?


author: Andy Heinzer
body: 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.


author: Uncleweb
body: HI [@Andy Heinzer](/t5/user/viewprofilepage/user-id/541137)

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](https://community.atlassian.com/t5/image/serverpage/image-id/304223i1FF4B32C07C682F0/image-size/large?v=v2&px=999 "apiresult.JPG")


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


author: Andy Heinzer
body: 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.


author: Uncleweb
body: Thanks [@Andy Heinzer](/t5/user/viewprofilepage/user-id/541137)

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


author: Nikola Perisic
body: Welcome to the community [@Uncleweb](/t5/user/viewprofilepage/user-id/5420093) !

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.

comments: author: Uncleweb
body: [@Nikola Perisic](/t5/user/viewprofilepage/user-id/5166624) 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?


author: Nikola Perisic
body: [@Uncleweb](/t5/user/viewprofilepage/user-id/5420093)

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


author: Uncleweb
body: yes


author: Uncleweb
body: 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


author: Nikola Perisic
body: 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.


author: Nikola Perisic
body: I added additional tags for wider visibility.


author: Uncleweb
body: Thanks [@Nikola Perisic](/t5/user/viewprofilepage/user-id/5166624)


Tags: cloud

community

confluence-cloud