Search code examples
powershellazure-devopsazure-pipelinesazure-devops-rest-apiworkitem

pass value to custom field in azure board task, user story etc


I have created a custom field on the ado board ,now I would like to pass value in to it using REST API, pls let me know if that is possible ?if so how? please look at the below screen shot for an example

enter image description here

How to pass value in to the custom field as highlighted in the screen shot via REST API


Solution

  • There is no custom endpoint for populating fields, they are part of the workitem endpoint on _apis/wit/workitems and can be passad along in the POST request when creating a workitem or updated through PATCH request

    Update the value of a field on an existing item

    If you want to update a field on an existing workitem, make a PATCH request to the following url

    https://dev.azure.com/{{ORGANIZATION}}/_apis/wit/workitems/{{ID}}?api-version=6.0
    

    With the following body (replace {{FIELDVALUE}} with the actual value you want to set). Fields not mentioned in the body will remain as is

    [
      {
        "op": "add",
        "path": "/fields/Custom.SysID",
        "value": "{{FIELDVALUE}}"
      }
    ]
    

    Set the field upon creation of the workitem

    If you are creating a workitem from scratch you make a POST request to

    POST https://dev.azure.com/{{ORGANIZATION}}/_apis/wit/workitems/Task?api-version=6.0
    

    The body is on the same format, but may contain other fields that should be initialized (like title):

    [
      {
        "op": "add",
        "path": "/fields/Custom.SysID",
        "value": "{{FIELDVALUE}}"
      },
      {
        "op": "add",
        "path": "/fields/System.Title",
        "value": "MyTitle"
      }
    ]