It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Can not create a release version via the REST API calls. Can create it manually.

Hello,

I'm trying to create a release version in JIRA via a REST API call.
I have access to do this manually from the UI.

I can also fetch the current release versions, so my session cookies should be OK.

Getting a 404 saying "errorMessages":["Project with key \\'XXX\\' either does not exist or you do not have permission to create versions in it." when try to do the POST.

Code below:-

 

import requests
import json
import getpass

user_name = input("Please enter your user name (Provide with quotes. Ex :- 'john.smith'):- ")
password = input("Please enter your password (Provide with quotes. Ex :- 'abc123'):- ")

response_init = requests.post("https://jira.xxx.com/rest/auth/1/session",
data='{ "username": "' + user_name + '", "password": "' + password + '" }',
headers={"Content-Type": "application/json"})

cookie_name = response_init.cookies._cookies['jira.xxx.com']['/']['JSESSIONID'].name
cookie_value = response_init.cookies._cookies['jira.xxx.com']['/']['JSESSIONID'].value

cookie = cookie_name + "=" + cookie_value

# I can fetch the current versions for the project. So I guess my access cookie is working.
response_get = requests.get("https://jira.xxx.com/rest/api/2/project/PNG/versions", headers={"Cookie": cookie})
print(response_get.text)

body = json.dumps({
"self": "http://jira.iress.com/rest/api/~ver~/version/33072",
"description": "Created @ CodeIT",
"name": "2019-Jul-WK28",
"archived": "false",
"released": "false",
"releaseDate": "2019-07-12",
"project": "XXX",
#"projectId": 33072,
"id": "33072",
"overdue": "false"
}
)

headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Bearer": cookie
}

# This is the request which is failing.
response_post = requests.request("POST", "https://jira.xxx.com/rest/api/2/version", data = body, headers = headers)


print response_post.status_code
if response_post.status_code == 200:
print "you did it!!"

 

 




2 answers

Viraj, hi!

 

Make sure that user, which creates version has all permissions for this.

Well as I mentioned this user can create it manually via the Web UI. It's only the REST call which is not working.

I saw this :-

https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-api-3-version-post

 

Anyone know what OAuth scopes means in there??

image.png

Are you sure your auth headers are right? I think you need something like:

"Authorization: Bearer " + cookie_value

HTH. 

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you