Reputation: 509
I'm trying to use the Jira API to update a custom field and it doesn't return an error, but also doesn't update the field.
We're using it as an Approval field and when an approver isn't selected, it's undef:
"customfield_10003": null
When it's set in the GUI it has a number of different values:
"customfield_10003" : [
{
"accountId": "xxx",
"accountType": "atlassian",
"active": true,
"avatarUrls": {
"16x16": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/611520f4e6e6f800717aefcf/b2bc0e5c-23e4-4cef-9854-09x83/16",
"24x24": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/611520f4e6e6f800717aefcf/b2bc0e5c-23e4-4cef-9854-0x283/24",
"32x32": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/611520f4e6e6f800717aefcf/b2bc0e5c-23e4-4cef-9854-xd283/32",
"48x48": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/611520f4e6e6f800717aefcf/b2bc0e5c-23e4-4cef-9854-xd283/48"
},
"displayName": "Person Name",
"emailAddress": "[email protected]",
"self": "https://oursite.atlassian.net/rest/api/2/user?accountId=x",
"timeZone": "US/Eastern"
}
],
Trying to test it from the command line returns no results:
curl --request PUT --url 'https://oursite.atlassian.net/rest/api/latest/issue/HELP-35' --user '[email protected]:x' --header 'Accept: application/json' --header 'Content-Type: application/json' --data '{ "update": { "customfield_10003": [ { "add": "emailAddress" } ] } }'
Looking for some suggestions on how I can add an approver via API.
Upvotes: 0
Views: 663
Reputation: 1560
It is basically a multi-picker user field and here is some example on updating that field:
{"customfield_10009": [ {"name": "charlie" }, {"name": "bjones" }, {"name": "tdurden" }]}
Remember to use POST
method when you are setting it directly.
However, in your case, you need to use PUT method and change your JSON like the "name" one. Please note that, you may face with this bug when in this case, you need to use request with "id" (or "accountId).
curl --location --request PUT 'https://{{base_url}}/rest/api/3/issue/{{issue_key}}' \
--header 'Authorization: Basic {{token}}' \
--header 'Content-Type: text/plain' \
--data-raw '{
"fields": {
"customfield_10003": [
{
"id": "<user id, like 5c508a2281ec9e450ceb0f9e>"
}
]
}
}'
Upvotes: 0