Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Getting HTML in API response, not json (status 200)

Arunava September 4, 2024 edited

Hi, I am trying to use Jira APIs for my company profile. I have a service account created and using a auth token. I am getting 200 response from jira APIs but its returning back with a HTML response of the logged in page (Dashboard page once the user is successfully logged in) and not the response for any specific API.

I have tried multiple APIs, I am using Postman to test these. Sharing one example of what I am trying (get all projects):

URL : https://jira.<company-name>.net/rest/api/3/project/

Method : GET

Authorization : Bearer token

Headers : Content-type and Accept as application/json

Please help with what needs to be changed to get the correct json response ?

2 answers

1 accepted

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

Hi @Arunava 

I understand you are trying to use a Personal Access Token to connect to Jira's REST, but it seems it's not working as expected.   The URL you posted seems to be trying to use a version 3 of the API.  However this doesn't align, as Jira Data Center/Server don't have a v3 of the REST API yet.  (Jira Cloud does have a v2 and v3 currently, but on premise editions of Jira only are using a v2 of REST API)

If you check the Jira Data Center platform REST API reference, you can see that these endpoints only use /2/ in the URL.   So I'd want to confirm that you are trying to connect to a Jira Data Center/Server instance first if you're using a PAT token, that should work.

If this is a Jira Cloud site, then there are different reference guides and different kinds of tokens to generate for the REST API calls.

Arunava September 5, 2024

Thank you so much @Andy Heinzer ... I am able to get the proper response using the v2! Cannot believe that was the issue... Thanks once again!

Like Andy Heinzer likes this
0 votes
Javier Martínez Caballero
Contributor
September 4, 2024

Hi Arunava!

Looks like the issue might be that your request is getting redirected to the login page instead of the API endpoint. Here’s what to try:

  1. Permissions: Make sure your service account has the right permissions for the API.

  2. URL Check: Double-check the URL, just in case something's off there.

  3. Token: Try generating a new API token or ensure your current one has proper access.

  4. SSO: If your company uses SSO, it could be interfering with the API. You might need to bypass that for API requests.

  5. Redirects: Postman might be following redirects. Turn that off or check the response headers to see if that’s what’s happening.

Give these a shot and you should start getting the proper JSON response instead of the login page!

Arunava September 5, 2024 edited

Hi Javier, thank you for the response.

  1. URL Check: URL is correct, confirmed that

  2. Token: Token is active and have checked it again (using a PAT created by logging into the UI for this user)

  3. SSO: We use SSO but for the service account that is not required. I am able to login to Jira UI using the username/password without SSO.

  4. Redirects: I have tried this, If I disable auto-redirect, it gives 302 status. 

I can confirm that the token is working. If I use the correct token and use auto-redirect, I get the HTML response for the logged in page (with the dashboard page with all the options for this user). If I use a invalid token, it responds back with the HTML of the login page.

Permissions - This is something which I don't have access to but was confirmed by admin team that all the necessary access is given. Can you please share if there are any specific permissions that I should ask them to check. Or if I am missing something else here.

Javier Martínez Caballero
Contributor
September 5, 2024

Hey Arunava!

Thanks for the update! It sounds like the token is working but something is still off. Since you're getting a 302 redirect, it’s likely pointing to an authentication issue or permissions.

Maybe you should ask them to verify the Browse Projects permission, for the service account on all relevant projects.

BR, Javier.

Arunava September 5, 2024

They claim that similar service accounts are using APIs and there are no specific settings to be changed but I am not sure. Anyway, thank you for the suggestions. Please let me know if you come across anything else which I might be missing here. 

Suggest an answer

Log in or Sign up to answer