Set assignee through REST API

Gabriele Calligaro February 12, 2019

Hello,

I've developped a small bot task to create an issue (type bug) on jira cloud using the API.

Creation and transition are working properly but I'm unable to assign the ticket through the API.

This is the message I'm getting while executing the PUT command

{"errorMessages":[],"errors":{"assignee":"Field 'assignee' cannot be set. It is not on the appropriate screen, or unknown."}}

My Jira administrator created a default screen for Bug types where Assignee field is not visible in creation and is not editable after creation. However, I can assign the ticket using the "Assign" button present in the screen and I can edit directly the assignee box when opening the issue from the backlog board.

Is there a way to change the assignee through the API when in such scenario?

Thanks

 

7 answers

1 accepted

1 vote
Answer accepted
tomd
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 13, 2019

Hello Gabriele,

Please take a look on this thread and let us know if it's helpful in your case.

Tom

Gabriele Calligaro February 13, 2019

Hi Tom,

thanks for your feedback. I issued the editmeta get and retrieved the list of fields (see below). Assignee is not part of the list. In the mentioned thread is suggested to add the field on the edit issue screen. Is this something I can do as Project administrator or should I pass through jira administrator? I suspect edit layout is due to the "default bug" set by my administrator.

Thanks

 

{
"fields": {
"summary": {
"required": true,
"schema": {
"type": "string",
"system": "summary"
},
"name": "Summary",
"key": "summary",
"operations": [
"set"
]
},
"environment": {
"required": false,
"schema": {
"type": "string",
"system": "environment"
},
"name": "Environment",
"key": "environment",
"operations": [
"set"
]
},
"attachment": {
"required": false,
"schema": {
"type": "array",
"items": "attachment",
"system": "attachment"
},
"name": "Attachment",
"key": "attachment",
"operations": []
},
"versions": {
"required": false,
"schema": {
"type": "array",
"items": "version",
"system": "versions"
},
"name": "Affects Version/s",
"key": "versions",
"operations": [
"set",
"add",
"remove"
],
"allowedValues": []
},
"description": {
"required": false,
"schema": {
"type": "string",
"system": "description"
},
"name": "Description",
"key": "description",
"operations": [
"set"
]
},
"issuelinks": {
"required": false,
"schema": {
"type": "array",
"items": "issuelinks",
"system": "issuelinks"
},
"name": "Linked Issues",
"key": "issuelinks",
"autoCompleteUrl": "https://mydomain.atlassian.net/rest/api/2/issue/picker?currentProjectId=&showSubTaskParent=true&showSubTasks=true&currentIssueKey=RAV-67&query=",
"operations": [
"add"
]
},
"comment": {
"required": false,
"schema": {
"type": "comments-page",
"system": "comment"
},
"name": "Comment",
"key": "comment",
"operations": [
"add",
"edit",
"remove"
]
},
"fixVersions": {
"required": false,
"schema": {
"type": "array",
"items": "version",
"system": "fixVersions"
},
"name": "Fix Version/s",
"key": "fixVersions",
"operations": [
"set",
"add",
"remove"
],
"allowedValues": []
},
"priority": {
"required": false,
"schema": {
"type": "priority",
"system": "priority"
},
"name": "Priority",
"key": "priority",
"operations": [
"set"
],
"allowedValues": [
{
"self": "https://mydomain.atlassian.net/rest/api/3/priority/1",
"iconUrl": "https://mydomain.atlassian.net/images/icons/priorities/critical.svg",
"name": "Highest",
"id": "1"
},
{
"self": "https://mydomain.atlassian.net/rest/api/3/priority/2",
"iconUrl": "https://mydomain.atlassian.net/images/icons/priorities/medium.svg",
"name": "High",
"id": "2"
},
{
"self": "https://mydomain.atlassian.net/rest/api/3/priority/3",
"iconUrl": "https://mydomain.atlassian.net/images/icons/priorities/medium.svg",
"name": "Medium",
"id": "3"
},
{
"self": "https://mydomain.atlassian.net/rest/api/3/priority/4",
"iconUrl": "https://mydomain.atlassian.net/images/icons/priorities/low.svg",
"name": "Low",
"id": "4"
},
{
"self": "https://mydomain.atlassian.net/rest/api/3/priority/5",
"iconUrl": "https://mydomain.atlassian.net/images/icons/priorities/lowest.svg",
"name": "Lowest",
"id": "5"
}
]
}
}
}

Like Shrinish likes this
Gabriele Calligaro February 13, 2019

Hi Tom,

I found how to do it

PUT https://mydomain.atlassian.net/rest/api/3/issue/RAV-67/assignee

{
"name": "gabriel"
}

Finally issue get assigned

Thanks for your help.

Like # people like this
tomd
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 13, 2019

Perfect, glad you were able to solve it.

Thank you, Gabriele, for the confirmation!

Tom

Gabriele Calligaro February 13, 2019

Tom, just a question, is it normal that I don't get a response from the API?

For sure it is working as I see the issue assigned to the right person but while testing on postman (and on my RPA solution as well) the response is empty.

tomd
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 13, 2019

Gabriele,

According to the documentation, it looks like the body of the response should be empty in that case, and HTTP 204 status code is expected.

Tom

Like Gabriele Calligaro likes this
Gabriele Calligaro February 13, 2019

Perfect, thanks.

Regards

Rajkumar Balakrishnan May 24, 2020

This {"name": "gabriel"} example by using an appropriate userid or name is not working at least for me anymore.

The documentation here suggests to use the following:

assignee.png

Like # people like this
Rajkumar Balakrishnan July 14, 2020

I figured out and use the following R script consistenetly to assign a assignee:

library(httr)
library(RJSONIO)

x <- list(fields = list(project = c(key = "MAN"),
summary = "Testing Assignee",
description = "Testing Assignee",
issuetype = c(name = "Task"),
assignee = c(accountId = "12345:accac345-5657-asg4-t5t5-9c6exxxxe7ba")

))
response <- POST("https://companyname.atlassian.net/rest/api/2/issue/",body = RJSONIO::toJSON(x),
authenticate(username, jira_passcode, "basic"),
add_headers("Content-Type" = "application/json"), verbose())

5 votes
Demiank100 August 14, 2020

this is using rest API in python but first i query the assignee possible for a ticket and extracted the assignee_id, then that's what i use to update the ticket

 

print("-----------getting the assigne ID")
user_id_q = "my_site/rest/api/2/user/assignable/search?issueKey={0}&query={1}".format(my_issue, my_user)
response = requests.get(user_id_q, auth=(config.USER, config.TOKEN))
accound_id = response.json()[0]["accountId"]

print("updating the assignee")
assigne = {"fields": {"assignee": {"accountId": accound_id}}}
assigne_url = "my_site/rest/api/2/issue/my_issue"
response = requests.put(assigne_url, auth=(config.USER, config.TOKEN), json=assigne)


 i translated from:

https://community.atlassian.com/t5/Jira-questions/Assignee-set-to-unassigned-while-creating-ticket-through-the/qaq-p/1310631

1 vote
מרים לרנר December 6, 2022
if key == "assignee":
            value = {"name": value}
fields = {key: value}
       
jira.update_issue_field(jira_id, fields)
Works for me.
1 vote
Robert Ross July 13, 2020

Second to @Rajkumar Balakrishnan  , @tomd can you please advise here? The documentation for sending assignee / reporter with an ID does not assign or even return an error.

 

For example:

{
"fields": {
"summary": "another one",
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": ""
}
]
}
]
},
"project": {
"id": "10002"
},
"issuetype": {
"id": "10004"
},
"labels": [
"firehydrant",
"UNSET"
]
},
"assignee": {
"id": "5c17a8f436647b5b9100d446"
}
}


 

This payload is correct, the ID for assignee exists, however the ticket gets created without an assignee. When we assign a user via the UI and then request the issue via the API, it matches the account ID on the issue payload. So we know the record ID is correct.

The documentation just seems straight up wrong. Why is this so consistent with your APIs?

Rajkumar Balakrishnan July 14, 2020

Hi @Robert Ross, please check my answer above for a clue on how to assign an assignee. It should not be difficult to port the R script to curl command.

0 votes
pranay Kumar September 23, 2020

Hi Team,

It will work when we assign the issue using account id of assignee.

We will get assignee using GET method

Here i tried with following details and it worked

PUT method: Response: /rest/api/2/issue/TEST-13

Body: 

{
"accountId": "5ba9ceb37add096a823180a6"

}

0 votes
Rajkumar Balakrishnan May 24, 2020
{
      "accountId": "5b109f2e9729b51b54dc274d"
    }

works. 

{
      "name": "gabriele.calligaro"
    }

is failing since recently. The documentation mentions the following:

{
      "id": "5b109f2e9729b51b54dc274d"
    }

fails.

0 votes
Shrinish July 2, 2019

PUT https://mydomain.atlassian.net/rest/api/3/issue/RAV-67/assignee

{
"name": "gabriel"
}

Finally issue get assigned

 

This does not work as expected !

Could you please share the snippet of the code

Gabriele Calligaro July 2, 2019

Hi Shrinish,

the code is the one you have above.

What i do is to create an issue with

POST https://mydomain.atlassian.net/rest/api/2/issue

{
    "fields": {
       "project":
       {
          "key": "RAV"
       },
       "summary": "TEST",
       "description": "TEST",
       "issuetype":
       {
          "name": "Bogue"
       },
       "priority":
      {
          "name": "Highest"
      } 
   }
}

 

This will give me the issue key (suppose RAV-67) and using the key I perform the assignment

 

PUT https://mydomain.atlassian.net/rest/api/3/issue/RAV-67/assignee

{
 "name": "gabriele.calligaro"
}

If this doesn't works you should check with the Atlassian support (more skilled then me) and/or your jira administrator (maybe you are not authorized to assign issue)

Hope it helps

 

P.S: please use only atlassian community to contact me

Like Shrinish likes this
Shrinish July 2, 2019

Thank You !

Shrinish July 2, 2019

.

Suggest an answer

Log in or Sign up to answer