Getting HTML in API response, not json (status 200)
Asked by Arunava:

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 ?


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

I understand you are trying to use a [Personal Access Token](https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html) 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](https://docs.atlassian.com/software/jira/docs/api/REST/9.17.0/), 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](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#version) and different kinds of tokens to generate for the REST API calls.

comments: author: Arunava
body: Thank you so much [@Andy Heinzer](/t5/user/viewprofilepage/user-id/541137) ... I am able to get the proper response using the v2! Cannot believe that was the issue... Thanks once again!


author: Javier Martinez Caballero
body: 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!

comments: author: Arunava
body: 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.


author: Javier Martinez Caballero
body: 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.


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


Tags: api

jira-unknown-hosting-type

unknown-hosting-type