JIRA API throws 404 most of the times
Asked by Deep Amin:

Hi,   

I am trying to use transitions API to get and post transitions using postman with Base 64 encoded username and API token and it works fine every time. When I try to automate the flow in gitlab CI with python it worked for some time but now it throws  
"404  
{"errorMessages":\["Issue does not exist or you do not have permission to see it."\],"errors":{}}" most of the time. I am using the same username/token base64 combination, I have tried using the requests library in python to make the requests and also python Jira library and the issue is persistent.   
What should be the way to further debug it? Is there any known solution?  

Thank you!


Answers:
author: Deep Amin
body: Hi Marc,   

Sure, the token is active as I am using the same token with Postman and it works.   
The calls are as follows:  

Postman:

GET

https://\<company_jira_server\>/rest/api/2/issue/\<issue_id\>/transitions

Headers:  
Authorization: Basic \<base64(user:token)\>  

Python:  

```
transitions_url = f"{jira_base_url}/issue/{issue_key}/transitions"
headers = {
    "Authorization": f"Basic {jira_auth}"
}
transitions_response = requests.get(transitions_url, headers=headers)
if transitions_response.status_code == 200:
    transitions = transitions_response.json()
else:
    print(f"Failed to fetch transitions: {transitions_response.status_code}")
    print(transitions_response.text)
```

where jira_base_url = f"{jira_server}/rest/api/2/" and jira_server is the company jira server, the issue_key is the Jira issue id and  

```
jira_auth = base64.b64encode(f"{jira_user}:{jira_token}".encode()).decode()
```


author: Tuncay Senturk
body: Hello [@Deep Amin](/t5/user/viewprofilepage/user-id/5582893)

Welcome to the Community!

The error you're facing can be tricky to debug, especially since it worked for some time and then started failing. There should be some change related to your code or the environment but what I'd first ensure that the issue ID or key you are trying to access is correct and exists. Trying with another issue key may give us a clue.

I'd also verify that the user associated with the API token still has the necessary permissions to view the issue. If you haven't done yet.

There might be network-related issues (DNS, proxy settings, etc.) in your CI environment that aren't present in your local environment. It would also be helpful to isolate the request in a simple Python script outside of GitLab CI to verify it's not a CI-specific issue. If it works in isolation but fails in CI, the issue might be with the CI environment itself.

Sorry, if I wasn't helpful but these are the clues that came to my mind.

comments: author: Deep Amin
body: I have tried with multiple issues as the automation pertains to more than one project and it happens for all of them. I can verify the token permissions with Postman the same rest call works fine. I will try to isolate the script as per your recommendation, however if that was to be the case it would never have worked in CI environment, which is not the case. Thank you in any case for the pointer.


author: Marc - Devoteam
body: Hi [@Deep Amin](/t5/user/viewprofilepage/user-id/5582893)

The errors are related to permissions.

Is your token still active or has it expired?

Can you also show the call you are making via postman and python, this will help members on the community.

They might see issues in the call.


Tags: cloud

jira-cloud