Jira Cloud API无法更新审批类自定义字段 求解决方法
解决Jira API更新自定义审批字段无效的问题
问题根源
你当前的请求体格式错误:该自定义字段是多用户选择类型(值为用户对象数组),不能直接通过add传入字符串(如邮箱)来添加用户。Jira API对这类字段的更新要求传入包含accountId的用户对象,而非简单字符串。
正确的API调用方式
根据字段当前的状态,选择对应的更新方式:
1. 字段为空(值为null)时,设置审批人
使用set操作直接覆盖字段值为用户对象数组:
curl --request PUT \ --url 'https://oursite.atlassian.net/rest/api/2/issue/HELP-35' \ --user 'bot@oursite.com:x' \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --data '{ "update": { "customfield_10003": [ { "set": [ { "accountId": "xxx" } ] } ] } }'
2. 字段已有审批人时,添加新审批人
使用add操作追加用户对象到数组中:
curl --request PUT \ --url 'https://oursite.atlassian.net/rest/api/2/issue/HELP-35' \ --user 'bot@oursite.com:x' \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --data '{ "update": { "customfield_10003": [ { "add": { "accountId": "yyy" } } ] } }'
3. 清空审批字段
如果需要移除所有审批人,用set操作设为[]空数组:
curl --request PUT \ --url 'https://oursite.atlassian.net/rest/api/2/issue/HELP-35' \ --user 'bot@oursite.com:x' \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --data '{ "update": { "customfield_10003": [ { "set": [] } ] } }'
关键注意事项
- 必须使用
accountId标识用户,而非邮箱或显示名称,这是Jira API推荐的用户唯一标识方式。 - 确保调用API的账号拥有编辑该字段的权限,否则可能出现无报错但无更新的情况。
- 建议使用
/rest/api/2/issue/而非/rest/api/latest/issue/,避免因API版本变更导致的兼容性问题。
内容的提问来源于stack exchange,提问作者Jeremy Wilson
相关产品推荐
相关产品推荐

