You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Jira创建Issue的API请求Payload中忽略额外字段?

解决Jira API创建Issue时多余字段报错的问题

你遇到的这个问题很典型——用了包含所有Issue类型字段的通用POJO,结果创建Story时,那些属于Support Incident的字段被Jira判定为“不在对应屏幕上”,直接返回校验错误。先把你的报错信息贴出来方便参考:

{ "errorMessages": [], "errors": { "key1": "Field 'key1' cannot be set. It is not on the appropriate screen, or unknown.", "key2": "Field 'key2' cannot be set. It is not on the appropriate screen, or unknown.", "customfield_10216": "Field 'customfield_10216' cannot be set. It is not on the appropriate screen, or unknown.", "customfield_21263": "Field 'customfield_21263' cannot be set. It is not on the appropriate screen, or unknown.", "customfield_10704": "Field 'customfield_10704' cannot be set. It is not on the appropriate screen, or unknown.", "customfield_10212": "Field 'customfield_10212' cannot be set. It is not on the appropriate screen, or unknown." } }

下面给你两个最直接的解决方案,按需选择:

方案1:动态过滤请求体字段(推荐长期维护)

Jira的每个Issue类型对应的创建屏幕字段都是不同的,最规范的做法是根据当前要创建的Issue类型,动态筛选出有效字段再发送请求:

  • 先调用Jira的/rest/api/3/issue/createmeta接口,传入你的项目key和目标IssueType的ID,获取该类型Issue创建时允许的所有字段列表(包括系统字段和自定义字段)。
    示例请求:GET /rest/api/3/issue/createmeta?projectKeys=YOUR_PROJECT_KEY&issuetypeIds=STORY_ID&expand=projects.issuetypes.fields
  • 拿到有效字段列表后,遍历你的通用POJO,只保留存在于这个列表中的字段,构建干净的请求体再调用创建Issue的API。
  • 好处是完全符合Jira的校验规则,不会有冗余字段,也能避免后续字段变更带来的潜在问题。

方案2:开启Jira API的忽略未知字段参数(快速解决)

如果你不想改太多代码,Jira API本身提供了一个参数可以直接跳过这些无效字段的校验:

  • 在调用创建Issue的POST请求时,在URL末尾加上?ignoreUnknownFields=true。
    示例请求URL:POST /rest/api/3/issue?ignoreUnknownFields=true
  • 这个参数会告诉Jira:请求体里的未知/不在当前屏幕的字段直接忽略,只处理有效字段。
  • 注意:这个参数只会忽略“不存在/不在屏幕”的字段,如果是该Issue类型必填的字段你没传,还是会正常报错,不用担心跳过必要校验。

如果你用的是Atlassian官方的Jira Java客户端(jira-rest-java-client),也可以在客户端配置里开启这个选项:

RestClientConfig config = RestClientConfig.newBuilder()
    .setIgnoreUnknownFields(true)
    .build();
JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
JiraRestClient client = factory.createWithBasicHttpAuthentication(jiraUrl, username, password, config);

内容的提问来源于stack exchange,提问作者Shivanshu Goyal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 20:07:52