Jakub
Jakub

Reputation: 127

How do I create a new field for given WorkItem with AzureDevOps REST API?

I want to create a custom Extension for AzureDevops. I'm using TypeScript SDK from Microsoft, unfortunately there is no method for creating a field, only for updating existing fields.

In Docs I found there's this endpoint: https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work-items/get-work-item?view=azure-devops-rest-7.1&tabs=HTTP for fetching given WorkItem along with its fields and their values.

There are also other endpoints nearby, but they only allow me to manipulate on fields that already exist, how can I create a brand new field for a WorkItem ?

Upvotes: 0

Views: 397

Answers (1)

Kevin Lu-MSFT
Kevin Lu-MSFT

Reputation: 35514

how can I create a brand new field for a WorkItem ?

To meet your requirement, you can use the following two Rest APIs to create and add the new field to work item type.

Step1: Create New work item field: Fields - Create

POST https://dev.azure.com/{organization}/_apis/wit/fields?api-version=7.0

Request Body:

{
  "name": "New Work Item Field",
  "referenceName": "SupportedOperations.GreaterThanEquals",
  "description": null,
  "type": "string",
  "usage": "workItem",
  "readOnly": false,
  "canSortBy": true,
  "isQueryable": true,
  "supportedOperations": [
    {
      "referenceName": "SupportedOperations.Equals",
      "name": "="
    }
  ],
  "isIdentity": true,
  "isPicklist": false,
  "isPicklistSuggested": false,
  "url": null
}

Step2: Add the new Work item field to work item type: Fields - Add

POST https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workItemTypes/{witRefName}/fields?api-version=7.1-preview.2

Request Body:

{
  "referenceName": "SupportedOperations.GreaterThanEquals",
  "defaultValue": "",
  "allowGroups": false
}

You can use the following two Rest API to get the ProcessID and Workitemref.

Processid: Processes - List Workitemref:Work Item Types - Get Work Item Types

Upvotes: 1

Related Questions