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

Problems with changing assignee (REST API) Edited

#BASH CODE

#!/bin/bash

jira_user="ID"
jira_pw="PASS!"
jira_server="jira.test.com"
jira_key="SECURITY-2480"
assignee="yccheon"

curl -D- -u "$jira_user":"$jira_pw" -X PUT -H "Content-Type: application/json" https://$jira_server/rest/api/2/issue/$jira_key --data '{"fields": {"assignee":{"name":"$assignee"}}}'

 

 

 

[incle@incle jira]$ ./jiraa.sh
HTTP/1.1 400 Bad Request
Server: nginx
Date: Tue, 04 Sep 2018 09:10:19 GMT
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
X-AREQUESTID: 1090x2941986x4
X-ASEN: SEN-2024910
Set-Cookie: JSESSIONID=63DEFAB473D458CFB183DFE55BFE8EC5; Path=/; HttpOnly
X-Seraph-LoginReason: OK
Set-Cookie: atlassian.xsrf.token=BSLJ-Y93F-8O6L-OULL|f95e7e2957b816674023cce36edb66d695e0f75d|lin; Path=/
X-ASESSIONID: ljee1t
X-AUSERNAME: yccheon
Cache-Control: no-cache, no-store, no-transform
X-Content-Type-Options: nosniff

{"errorMessages":[],"errors":{"assignee":"User '$assignee' does not exist."}}[incle@incle jira]$

 

 

 

I am worried about changing the assignment after creating JIRA.
Failed.


I have since found an API for changing assignments
I made the following error message

Please solve the problem

 

 

1 answer

1 vote
maumau Atlassian Team Sep 05, 2018

Hello there!

I think the issue is that in Bash, everything inside single quotes is preserved literally, without exception, so you're basically sending the literal "$assignee" as the name of the assignee and not the actual variable value "yccheon".

I tried the workaround mentioned in stackoverflow, but I got a different error. The solution was to use double quotes in the payload and then escape the inside quotes("{\"name\":\"$assignee\"}").

#!/bin/bash
jira_user="ID"
jira_pw="PASS!"
jira_server="jira.test.com"
jira_key="SECURITY-2480"
assignee="yccheon"

curl -D- -u "$jira_user":"$jira_pw" -X PUT -H "Content-Type: application/json" https://$jira_server/rest/api/2/issue/$jira_key/assignee -d "{\"name\":\"$assignee\"}"

I also changed the API call to this "PUT /rest/api/2/issue/{issueIdOrKey}/assignee" because it's easier to use, the payload is simpler.

Kind regards,
Maurício Karas

Thank you for your reply.

But I still have not solved it.
I'm trying to create a new JIRA TIKET
I'm not trying to change the existing JIRA ASSIGNEE.

I want you to make ASSIGNEE to me (ASSIGNEE TO MEE) when I create a new JIRA.

Help me.

maumau Atlassian Team Sep 06, 2018

Then the API call should be "POST /rest/api/2/issue" and the payload can be something like the following:

{"fields":{
"summary":"This is the Summary",
"project":{"key":"SECURITY"},
"description":"This is the Description",
"issuetype": {"name": "Task"},
"assignee": {"name": "yccheon"}
} }

 You can also send more information in the payload, check the REST API reference documentation for more details.

Unfortunately, with the REST API, you need to specify the username of the assignee, there's no way to have something similar to the "assign to me" in the GUI.

Kind regards,
Maurício Karas

maumau Atlassian Team Sep 06, 2018

Also, in this case, since the payload could be big, I recommend saving it in a ".json" file and your bash script can be like this:

#!/bin/bash

jira_user="ID"
jira_pw="PASS!"
jira_server="jira.test.com"

curl -D- -u "$jira_user":"$jira_pw" -X POST -H "Content-Type: application/json" https://$jira_server/rest/api/2/issue -d @payload.json

The "@payload.json" is referencing the json file with the actual payload, this is good because it also avoids the single quote issue that you were having.

Kind regards,
Maurício Karas

Can you help me with setting assignee field in the web API. I do not know how exactly to fetch the names from the JIRA website for the assignee. i want to fetch those names from JIRA and then parse it on the web tool which talks to JIRA. It can fetch the version and the projects but not the list of the names of the assignee. I have tried the above solutions but somehow it doesnt work

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Calling all Jira Cloud users! Give us feedback on our exploration of a new navigation.

Hi everyone! My name’s Matt and I’m a product manager at Atlassian. I work in the navigation & findability space for all our Jira Cloud products. We’ve been working on trying to improve the exp...

1,060 views 16 12
Join discussion

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