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

使用Azure DevOps REST API向继承流程工作项类型添加自定义字段报错

问题:Azure DevOps REST API 添加全局自定义字段到继承流程工作项类型失败

我正在使用Azure DevOps REST API自动化继承流程中工作项类型的自定义操作,具体是将现有全局自定义字段(如Custom.Name)添加到继承流程中的特定工作项类型(如Feature)。

调用POST /work/processes/{processId}/workItemTypes/{witRefName}/fields端点时,出现以下错误:

Error: Failed to add field Custom.Name. Status: MethodNotAllowed, Details: {"count":1,"value":{"Message":"The requested resource does not support http method 'POST'."}}

相关代码片段:

定义baseUrl的代码:

string baseUrl = $"https://dev.azure.com/{config.Organization}/_apis";

请求逻辑代码:

string url = $"{baseUrl}/work/processes/{processId}/workItemTypes/{witRefName}/fields?api-version=7.1-preview.1";
Console.WriteLine(url);

Console.WriteLine(fieldReferenceName);

var data = new
{
    referenceName = fieldReferenceName,//Ex. Custom.Name
    defaultValue = "", 
    allowGroups = false
};

var response = await _client.PostAsync(url, new StringContent(JsonSerializer.Serialize(data), Encoding.UTF8, "application/json"));

解决方案

该错误的核心原因是目标API端点不支持POST方法。在Azure DevOps REST API中,将全局自定义字段添加到继承流程的工作项类型,需要使用PUT方法发起请求。

修正后的请求代码:

// 仅需将PostAsync替换为PutAsync,其余代码保持不变
var response = await _client.PutAsync(url, new StringContent(JsonSerializer.Serialize(data), Encoding.UTF8, "application/json"));

补充说明:

  • 针对继承流程的工作项类型字段配置操作(添加/更新),Azure DevOps API统一采用PUT方法,POST方法仅适用于创建全新字段的场景
  • 请求体中的参数结构无需调整,保持现有定义即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 19:39:57