从 CRM 到 Team Foundation Server 2018 的集成

Integration from CRM to Team Foundation Server 2018

我们有 CRM,客户可以在其中创建工单(变更请求、事件...)。 在开发团队方面,我们有 Team Foundation Server 2018。

为了加快流程,我们希望将整个过程自动化。因此,当客户创建工单时,自动创建 TFS 用户故事。

我们开发了代码,每次创建工单时,都会将数据放入 JSON 文件中。 (会在Github附上代码,分享一个link) 但是现在,我只需要信息,有人知道 JSON 文件应该是什么样子,需要 post 到 TFS 才能创建新的用户故事。

{
    "fields": {
        "System.WorkItemType": "User Story",
        "System.AreaPath": "EJ2TFS",
        "System.TeamProject": "EJ2TFS",
        "System.IterationPath": "EJ2TFS",
        "System.State": "New",
        "System.Reason": "New",
        "Microsoft.VSTS.Common.StateChangeDate": "2019-01-01T00:00:00Z",
        "System.ChangedBy": "Doe, John <firm\doej>",
        "System.CreatedBy": "Doe, John <firm\doej>",
        "System.Title": "Sample task created by POST API",
        "System.Discussion":"test1",
        "Microsoft.VSTS.Common.StateChangeDate": "2019-01-31T14:00:00",
        "Microsoft.VSTS.Common.Priority": 2,
        "Microsoft.VSTS.Common.ValueArea": "Business"
    }
}   

错误是:

{
    "$id": "1",
    "innerException": null,
    "message": "The request indicated a Content-Type of \"text/plain\" for method type \"POST\" which is not supported. Valid content types for this method are: application/json-patch+json.",
    "typeName": "Microsoft.VisualStudio.Services.WebApi.VssRequestContentTypeNotSupportedException, Microsoft.VisualStudio.Services.WebApi",
    "typeKey": "VssRequestContentTypeNotSupportedException",
    "errorCode": 0,
    "eventId": 3000
}

看来您的负载需要改造。我参考了几个代码示例并分享了这个片段。 (请测试这个,我没有机会测试它)

POST https://dev.azure.com/fabrikam/{project}/_apis/wit/workitems/$User Story?api-version=5.0

[
  {
    "op": "add",
    "path": "/fields/System.Title",
    "from": null,
    "value": "My first user story"
  }
]

MS documentation example

GitHub sample