Problems with changing assignee (REST API)

Incle YC September 4, 2018

#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
Mauricio Karas
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 5, 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

Incle YC September 6, 2018

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.

Mauricio Karas
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 6, 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

Mauricio Karas
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 6, 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

Shrinish July 3, 2019

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

Artūras Kravčenko February 17, 2020

Now neme of parameter is "accountId" insted of  "name".

Like Dylan Brophy likes this

Suggest an answer

Log in or Sign up to answer