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

Incle YC Sep 04, 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 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

Incle YC Sep 06, 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 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

Mauricio Karas 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

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Jira

Try Jira Cloud for Outlook: Organize your work without leaving your inbox

Hi Atlassian community, My name is Max and I work on the product integration team at Atlassian. I am pleased to announce the early access program for the Jira Cloud add-in for Outlook. This add-in...

790 views 0 12
Read article

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