Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Problem on creating issues with Jira REST API using Oauth2 access_token.

Deleted user January 2, 2019

I need to create issue using Jira REST API via Oauth2 authentication process. I have followed each and every steps from https://developer.atlassian.com/cloud/jira/platform/oauth-2-authorization-code-grants-3lo-for-apps.

I have created the jira app to configure Oauth2 details with all the oauth scopes(Please note that I'm not an admin user). I can able to generate Oauth2 access_token and refresh_token.

When I tried to create issue using the access_token by referring https://developer.atlassian.com/cloud/jira/platform/rest/v3#api-api-3-issue-post, I am not able to create any issues to my jira project. Details as follow.

Python Request:

url = 'https://'+ domain +'.atlassian.net/rest/api/3/issue'
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Bearer': <access_token>}
payload = <payload>
response = requests.post(url, json=payload, headers=headers)

When I provided

payload={"fields":{"project":{"key":"CTP"}}}

status code = 400 and Error received = {"issuetype":"issue type is required"}.

when payload updated to

payload={"fields":{"project":{"key":"CTP"},"issuetype":{"name":"Task"}}}

status code = 401 and Error received = "issuetype":"The issue type selected is invalid.","project":"Anonymous users do not have permission to create issues in this project. Please try logging in first."
Note that the issue type 'Task' is available in CTP project.

when payload updated to

payload={"fields":{"project":{"key":"CTP"},"issuetype":{"name":"Task"},"summary":"summary","description":"description","priority":{"name": "High"}}}

status code = 400 and Error received = {"summary":"Field 'summary' cannot be set. It is not on the appropriate screen, or unknown.","description":"Field 'description' cannot be set. It is not on the appropriate screen, or unknown.","priority":"Field 'priority' cannot be set. It is not on the appropriate screen, or unknown."}

Curl Request:

curl --request POST \
--url 'https://domain.atlassian.net/rest/api/3/issue' \
--header 'Authorization: Bearer <access_token>' \
--header 'Content-Type: application/json' \
--data '<payload>'

For the above 3 payloads, the response received are same: {"message":"Client must be authenticated to access this resource.","status-code":401}

On the other hand If I try to get project details using the same access_token

curl --request GET \
--url https://api.atlassian.com/ex/jira/{cloudid}/rest/api/2/project \
--header 'Authorization: Bearer ACCESS_TOKEN' \
--header 'Accept: application/json'

I can get my project details successfully. Problem is only on creating the issues with Oauth2 access_token.

is anything I'm doing wrong?

Any help is appreciated. Thanks in advance.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events