I was struggling to update a variable group using the Azure DevOps Rest API. In this article I will document the procedure using POSTMAN.
First things first you should create a PAT in order to interact with the API. If you do not know how to create such a thing you should read my previous article about running a build through a REST api on which I documented also the creation of a PAT.
Then you will need to add the access token under authorization tab of POSTMAN using Type Basic Auth. The PAT should be added as plain text.
Then you will need to add Content-Type as application/json under Headers.
Then you will have to create your URL. This should be of the format:
Important: You should use the version=5.1-preview.1. If you use the latest version you will notice an error on the call. This is a bug that has not been fixed as I found online.
In my example I wanted to update the variable group with the ID 5 and add a variable named new-var. The body of your request should be like below. Keep in mind that we use the PUT HTTP verb to update the variable group. This means everything that is inside the variable group will be discarded. If you followed all the steps correctly you will notice the below output JSON. This should indicate success on the procedure.
Lastly you can locate your new variable inside the variable group.