update a custom field from API REST
Asked by Valentino GARCIA MENDEZ:

Hello everyone, I'm trying to make a script automatically assign a person to a custom field but it's not working. What am I doing wrong?

url: xxxx.atlassian.net/rest/api/2/issue/GRD-1152

json content:  

{ "fields": { "customfield_10280": "userId" } }


Answers:
author: Magdalena Zhisheva
body: Hi [@Valentino GARCIA MENDEZ](/t5/user/viewprofilepage/user-id/5536280) ,

Is the field a user picker (multiple users) or user picker (single user) type?

Moreover, do you have any other field or context where the user name/email is placed?  
Basically, you can achieve this with automation, but you have to send Web Request like this:  
"xxx.atlassian.net/rest/api/2/user/search?query={{\[where the user name is placed\].urlEncode}}"

and then to assign the user to your custom field, use this:

{{webResponse.body.first.accountid}}

Happy to help if you need more details!  

BR, Maggie

comments: author: Valentino GARCIA MENDEZ
body: The field is a user selector and has these fields:  
"customfield_10280": {  
"self": "https://\*\*\*\*\*.atlassian.net/rest/api/3/user?accountId=\*\*\*\*\*\*\*\*\*\*\*\*\*ff80c38a63f7",  
"accountId": "\*\*\*\*:\*\*\*\*\*\*-\*\*\*\*-ff80c38a63f7",  
"emailAddress": "\*\*\*\*\*@\*\*\*\*\*.com",  
"avatarUrls": {  
"48x48": "<https://secure.gravatar.com/avatar/f75d5a8f7ae2aa6f848b963eb5eb3066?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FVM-5.png>",  
"24x24": "<https://secure.gravatar.com/avatar/f75d5a8f7ae2aa6f848b963eb5eb3066?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FVM-5.png>",  
"16x16": "<https://secure.gravatar.com/avatar/f75d5a8f7ae2aa6f848b963eb5eb3066?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FVM-5.png>",  
"32x32": "<https://secure.gravatar.com/avatar/f75d5a8f7ae2aa6f848b963eb5eb3066?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FVM-5.png>"  
},  
"displayName": "Valentino GARCIA MENDEZ",  
"active": true,  
"timeZone": "America/Argentina/Buenos_Aires",  
"accountType": "atlassian"  
}  
Additionally, the editmeta is as follows:  

"customfield_10280": {  
"required": false,  
"schema": {  
"type": "user",  
"custom": "com.atlassian.jira.plugin.system.customfieldtypes:userpicker",  
"customId": 10280  
},  
"name": "Referente",  
"key": "customfield_10280",  
"autoCompleteUrl": "https://\*\*\*\*\*.atlassian.net/rest/api/1.0/users/picker?fieldName=customfield_10280\&fieldConfigId=10482\&projectId=10175\&showAvatar=true\&query=",  
"operations": \[  
"set"  
\]  
}  


author: Magdalena Zhisheva
body: Hi [@Valentino GARCIA MENDEZ](/t5/user/viewprofilepage/user-id/5536280) ,

Can you give some more context of what exactly you are trying to do with this field, i.e. are you trying to assign same user every time based on some conditions?


author: Valentino GARCIA MENDEZ
body: I am writing a Python script that, based on certain parameters, assigns that custom field to a person. To test how the PUT request would work, I am trying it out in Postman and it's not working for me yet. For now, I am always testing with the same accountID.


author: Valentino GARCIA MENDEZ
body: im trying this:  
{  
"update": {  
"customfield_10280": \[  
{  
"set": \[  
{  
"accountId": "712020:1e04ff52-bc5a-4d4d-9aee-fa8eba77718b"  
}  
\]  
}  
\]  
}  
}


Tags: api

api-rest

cloud

jira-cloud

python