DEV Community

subramn
subramn

Posted on

How to Create a product backlog item using Azure Dev Ops Restful API

Why? — Sharing some of the lessons with developer community on how to automate repeatable tasks with Azure Dev Ops Rest API.

You can apply this pattern to create work items, trigger builds, test cases etc.

IDE: Visual Studio Code

Tech Stack: C#, FlurlHttp, Azure Dev Ops Restful API

Prerequisites:

Account created in Azure Dev Ops: https://azure.microsoft.com/en-us/products/devops/?nav=min

API Reference : https://learn.microsoft.com/en-us/rest/api/azure/devops/?view=azure-devops-rest-7.1

Create a Team project with the name : DevOpsDemos with Version control as “Git” and Work item process as “Scrum”

Go to User settings >> Personal access tokens and generate a new token so that it can be used for accessing the api.

How the code is structed:

Image description

Step 1: Create a ASP.NET Core Minimal Web API with the following packages:

Image description

Step 2: Update appsettings.json as follows:

Image description

Step 3: Create a record with the name “AzureDevOpsSettings” to load the configuration from appsettings.json created in previous step.

Image description

Step 4: Create Azure Dev Ops Client Request class as follows:

Image description

Step 5: Create an Access Token Provider class with an interface as follows:

Image description

Image description

Step 6:

Create a AzureDevOpsHttpClientAdapter class with an interface as follows:

Image description

Image description

Image description

Image description

Image description

Step 7:

Create an AzureDevOpsServicesManager class with an interface as follows:

Image description

Image description

Image description

Step 8:

Create a ProductBacklog Controller with an HttpPost Attribute with 2 Parameters.

Image description

Step 9:

Now update the program.cs to wire everything up and dependencies are injected.

Image description

Step 10: Now run the app using dotnet run command.

Step 11:

Now we can use any http clients to send a request to http://localhost:5276/api/ProductBackLog?title=Test PBI&description=Test

Hope this helps.

Top comments (0)