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

Viraj Wijesooriya December 6, 2018

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

0 votes
Carl Yamamoto-Furst December 2, 2019

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

"Authorization: Bearer " + cookie_value

HTH. 

0 votes
Vasiliy Zverev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 6, 2018

Viraj, hi!

 

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

Viraj Wijesooriya December 9, 2018

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

Suggest an answer

Log in or Sign up to answer