locked
Unable to update custom workitem field using rest-api

    Question

  • Hi all,

    I'm following rest-api for workitem from Microsoft website, the update a field section, but I got an error below. Am I missing something? Please advise.

    https://www.visualstudio.com/en-us/docs/integrate/api/wit/work-items

    [string]$collectionurl = "http://mytfs2017.wageworks.local:8080/tfs/mycolleciton"
    
    $body = @"
    [
    {
        "op": "add",
        "path": "/fields/MyCustom.WorkItemField",
        "value": "12345"
    }
    ]
    "@
    
    $uri = "$($collectionurl)/_apis/wit/workitems/45366?api-version=1.0"
    Write-Host $uri
    $result = Invoke-RestMethod -Method Patch -ContentType application/json -Uri $uri -UseDefaultCredentials -Body $body

    Invoke-RestMethod : {"$id":"1","innerException":null,"message":"The request indicated a Content-Type of \"application/json\" for method type \"PATCH\" 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, Version=14.0.0.0, Culture=neutral,

    PublicKeyToken=b03f5f7f11d50a3a","typeKey":"VssRequestContentTypeNotSupportedException","errorCode":0,"eventId":3000}

    At C:\DevOps\UpdateWorkItemField.ps1:24 char:11

    + $result = Invoke-RestMethod -Method Patch -ContentType application/js ...

    +           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException

        + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

    Best Regards,

    Andy Pham


    Best Regards, Andy Pham


    • Edited by AndyPham Monday, November 20, 2017 7:15 PM
    Monday, November 20, 2017 7:14 PM

Answers

  • I just removed <EMPTY /> from work item field and it is working.

    Best Regards,

    Andy Pham


    Best Regards, Andy Pham

    • Marked as answer by AndyPham Monday, November 20, 2017 9:49 PM
    Monday, November 20, 2017 9:49 PM

All replies

  • I updated content-type to application/json-patch+json, and now got this error

    Here is my custom field in the work item

    <FIELD name="Build Definition Id" refname="MyCustom.WorkItemField" type="String" reportable="dimension">
            <EMPTY />
            <HELPTEXT>my custom field</HELPTEXT>
          </FIELD>

    invoke-RestMethod : {"$id":"1","customProperties":{"FieldReferenceName":"MyCustom.WorkItemField"},"innerException":null,"message":"TF401320: Rule Error for field my custom field. Error code:
    InvalidNotEmpty.","typeName":"Microsoft.TeamFoundation.WorkItemTracking.Server.RuleValidationException, Microsoft.TeamFoundation.WorkItemTracking.Server, Version=14.0.0.0, Culture=neutral,
    PublicKeyToken=b03f5f7f11d50a3a","typeKey":"RuleValidationException","errorCode":600171,"eventId":3200}
    At C:\DevOps\UpdateWorkItemField.ps1:22 char:11
    + $result = Invoke-RestMethod -Method Patch -ContentType application/js ...
    +           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
        + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

    Best Regards,

    Andy Pham


    Best Regards, Andy Pham

    Monday, November 20, 2017 7:26 PM
  • I just removed <EMPTY /> from work item field and it is working.

    Best Regards,

    Andy Pham


    Best Regards, Andy Pham

    • Marked as answer by AndyPham Monday, November 20, 2017 9:49 PM
    Monday, November 20, 2017 9:49 PM