Azure DevOps Rest API不保留System.AreaPath和System.IterationPath

问题描述

我正在尝试使用Azure DevOps(TFS)Rest API创建新的工作项。当我提交请求时,我发送的json数据具有AreaPath和Iteration路径的正确信息:

[
   {
      'op':'add','path':'fields/System.Title','from':null,'value':'Earthquake markers'
   },{
      'op':'add','path':'fields/System.WorkItemType','value':'Task'
   },'path':'fields/System.TeamProject','value':'UMC_Sitecore'
   },'path':'fields/System.AreaPath','value':'UMC_Sitecore\leaders'
   },'path':'fields/System.IterationPath','value':'UMC_Sitecore\49 Early Sept'
   },'path':'fields/System.Tags','value':'Pre-Grooming'
   },'path':'fields/System.Description','value':' test'
   }
]

但是,响应json认为AreaPath和迭代路径的TeamProject:

{
   {
      "System.WorkItemType":"Task","System.AreaPath":"UMC_Sitecore","System.TeamProject":"UMC_Sitecore","System.IterationPath":"UMC_Sitecore","System.State":"To Do","System.Reason":"New task","Microsoft.VSTS.Common.StateChangeDate":"1753-01-01T00:00:00Z","System.ChangedBy":{
         "displayName":"Romero,Tim","url":"https://code.umcom.org/UMCom_DefaultCollection/_apis/Identities/6d8a568d-3cf9-420b-9797-49b85b07b1f6","_links":{
            "avatar":{
               "href":"https://code.umcom.org/UMCom_DefaultCollection/_apis/GraPHProfile/MemberAvatars/win.Uy0xLTUtMjEtNjY3ODkyNjQ1LTgzMTIwMTE1Ni0yMDI1MzUwMDg3LTU5MDgw"
            }
         },"id":"6d8a568d-3cf9-420b-9797-49b85b07b1f6","uniqueName":"UMCOM_CENTRAL\\tromero","imageUrl":"https://code.umcom.org/UMCom_DefaultCollection/_api/_common/identityImage?id=6d8a568d-3cf9-420b-9797-49b85b07b1f6","descriptor":"win.Uy0xLTUtMjEtNjY3ODkyNjQ1LTgzMTIwMTE1Ni0yMDI1MzUwMDg3LTU5MDgw"
      },"System.CreatedBy":{
         "displayName":"Romero,"Microsoft.VSTS.Common.Priority":2
   },"_links":{
      "workItemType":{
         "href":"https://code.umcom.org/UMCom_DefaultCollection/5f12db4f-f69b-45ac-8d18-dcae5a3177ab/_apis/wit/workItemTypes/Task"
      },"fields":{
         "href":"https://code.umcom.org/UMCom_DefaultCollection/5f12db4f-f69b-45ac-8d18-dcae5a3177ab/_apis/wit/fields"
      }
   },"url":"https://code.umcom.org/UMCom_DefaultCollection/5f12db4f-f69b-45ac-8d18-dcae5a3177ab/_apis/wit/workItems"
}

我的json格式中是否存在某些错误,或者是否需要处理有关API的某些事情?

解决方法

尝试替换AreaPathIterationPath值:

  • 'value':'UMC_Sitecore\Leaders''value':'UMC_Sitecore\\Leaders'
  • 'value':'UMC_Sitecore\49 Early Sept''value':'UMC_Sitecore\\49 Early Sept'

反斜杠是JSON中的保留字符,您不能仅以这种方式使用它。

,

同意LJ。

此外,我建议您使用""而不是''。有关更多详细信息,请参阅此doc

骨架版本如下:

[
 {
 "op": "add","path": "/fields/System.Title","from": null,"value": "Sample Bug"
 },{
 "op": "add","path": "/fields/System.IterationPath","value": "test0002\\test02"
 },"path": "/fields/System.AreaPath","value": "test0002\\testa"
 }
]

结果:

enter image description here