Use the Work Item Tracking REST API (or .NET client) to create a work item of type Release by sending a JSON Patch document that sets all required fields so that no rules are violated. The exact required fields and rule conditions depend on the process and custom rules configured in the project, but the request structure is as follows.
Example HTTP request (REST API) to create a Release work item:
POST https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/$Release?api-version=7.0
Content-Type: application/json-patch+json
[
{
"op": "add",
"path": "/fields/System.Title",
"from": null,
"value": "Release 2024.04"
},
{
"op": "add",
"path": "/fields/System.Description",
"from": null,
"value": "Description of the release contents."
},
{
"op": "add",
"path": "/fields/Microsoft.VSTS.Common.Priority",
"from": null,
"value": 2
},
{
"op": "add",
"path": "/fields/Microsoft.VSTS.Scheduling.StartDate",
"from": null,
"value": "2024-04-10T00:00:00Z"
},
{
"op": "add",
"path": "/fields/Microsoft.VSTS.Scheduling.TargetDate",
"from": null,
"value": "2024-04-30T00:00:00Z"
},
{
"op": "add",
"path": "/fields/Custom.Approved",
"from": null,
"value": true
},
{
"op": "add",
"path": "/fields/Custom.ApprovedBy",
"from": null,
"value": "Release Manager"
},
{
"op": "add",
"path": "/fields/Custom.Risk",
"from": null,
"value": "Medium"
},
{
"op": "add",
"path": "/fields/Microsoft.VSTS.Scheduling.RemainingWork",
"from": null,
"value": 10
},
{
"op": "add",
"path": "/fields/Microsoft.VSTS.Scheduling.CompletedWork",
"from": null,
"value": 0
}
]
Key points based on the rule engine and validations:
- Use the
POST .../wit/workitems/$Releaseendpoint withContent-Type: application/json-patch+json. - Each field is added via a JSON Patch operation (
op: "add",path: "/fields/<refname>"). - To satisfy custom rules such as:
- “When a value is defined for Priority, make Risk required” – include both
Microsoft.VSTS.Common.Priorityand theCustom.Riskfield. - “When a change was made to Remaining Work, make Completed Work required” – include both
Microsoft.VSTS.Scheduling.RemainingWorkandMicrosoft.VSTS.Scheduling.CompletedWork. - “When the value of Approved is True, make Approved By required” – include both
Custom.ApprovedandCustom.ApprovedBy.
- “When a value is defined for Priority, make Risk required” – include both
- Do not set
bypassRules=true; rules must run to validate the work item.
Example using .NET WorkItemTrackingHttpClientBase.CreateWorkItemAsync:
using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
using Microsoft.VisualStudio.Services.WebApi.Patch;
using Microsoft.VisualStudio.Services.WebApi.Patch.Json;
var document = new JsonPatchDocument
{
new JsonPatchOperation
{
Operation = Operation.Add,
Path = "/fields/System.Title",
Value = "Release 2024.04"
},
new JsonPatchOperation
{
Operation = Operation.Add,
Path = "/fields/Microsoft.VSTS.Common.Priority",
Value = 2
},
new JsonPatchOperation
{
Operation = Operation.Add,
Path = "/fields/Custom.Risk",
Value = "Medium"
},
new JsonPatchOperation
{
Operation = Operation.Add,
Path = "/fields/Microsoft.VSTS.Scheduling.RemainingWork",
Value = 10d
},
new JsonPatchOperation
{
Operation = Operation.Add,
Path = "/fields/Microsoft.VSTS.Scheduling.CompletedWork",
Value = 0d
},
new JsonPatchOperation
{
Operation = Operation.Add,
Path = "/fields/Custom.Approved",
Value = true
},
new JsonPatchOperation
{
Operation = Operation.Add,
Path = "/fields/Custom.ApprovedBy",
Value = "Release Manager"
}
};
var client = new WorkItemTrackingHttpClient(new Uri("https://dev.azure.com/{organization}"), credentials);
var workItem = await client.CreateWorkItemAsync(
document,
project: "{project}",
type: "Release",
validateOnly: false,
bypassRules: false,
suppressNotifications: false,
userState: null,
cancellationToken: CancellationToken.None);
To ensure all rule validations are met in a specific project:
- Review the custom rules defined for the
Releasework item type in the process (for example, rules that make fields required based on other field values). - Include all required fields and any dependent fields in the JSON Patch document, following the patterns shown in the rule samples.
- Call
CreateWorkItemAsyncor the REST endpoint withbypassRulesset tofalse(or omitted) so the rule engine validates the request.
References: