Some REST API calls return 404 inconsistently

When utilizing Python to access the REST API for Jira Cloud I get inconsistent returned results. For instance, using the recommended Python code at https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-fields/#api-rest-api-3-field-get, I receive a proper returned response using the url: https://{company}.atlassian.net/rest/api/2/field.

However, when I try to get create metadata using guidance at https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-createmeta-projectidorkey-issuetypes-issuetypeid-get:

{
“errorMessages”: [
“You cannot create issues in this project.”,
“You are not authorized to perform this operation. Please log in.”
],
“errors”: {}
}

but on the same machine I can

curl -D- -u {user:token} -X GET -H “Content-Type: application/json” https://{company}.atlassian.net/rest/api/2/issue/createmeta/{project}/issuetypes

and receive a correct response. So anytime I try to get createmeta data from Python using requests the system will not adjudicate but it seems to be happy at all other times.

I’ve also tried recreating the reported information from successful curl runs

in Python with:

headers = {
“Accept”: “application/json”,
“Content-Type”: “application/json”,
‘transfer-encoding’: ‘chunked’,
‘connection’: ‘keep-alive’,
‘content-encoding’: ‘UTF-8’,
}

and using a session instead of a straight request like:

s = requests.Session()
s.auth=auth
s.headers=headers
s.proxies = {“http”: http_proxy,“https”: https_proxy}
s.verify = verify

response = s.get(url1)

NOTE:

  • Functionality is the same with both version 2 and 3 url constructs.
  • I have administrator access for the project in question
  • I’m using Python3.8.14 with Requests2.32.3
  • I’ve tried both General and Specific Jira access tokens
  • I’m on a Redhat 8.8 machine
  • Issuing the createmeta url in a browser on a Windows machine works.
  • Opening a session, issuing a get fields request followed by a createmeta request before closing the session also fails.

Hello @keithbenjamimicronco

My best guess is that your Python code is incorrect and you’re not constructing and sending the Basic Auth credentials properly.

If you look more closely at the documentation for the Get fields endpoint, you will see that it requires no authentication by default and can be accessed anonymously, so your request with faulty credentials is just being processed as unauthenticated (anonymous), which is leading you to think you have authenticated properly, when in fact you never did.

You’ve not said if the Get create metadata issuetypes endpoint is the only other one you’ve tried that is giving you an error about authentication. The fail-safe way to test whether your Python based requests are sending authentication properly is to start with a request to the Get Current User endpoint.