Using PAT token in ReleaseManagement REST API’s

Generating PAT Token:-

Step1: Generate PAT token by visiting your profile and selecting the right ReleaseManagement scope as per API need ( see 'Available scopes' section )

Step2: Copy the token generated after clicking 'Create Token' as shown in image above


Code which uses the generated PAT token above :-

public static async Task<string> GetReleaseDefinitionsUsingPATToken()
            var username = "nobody";
            var token = "<Give your PAT Token here>";

            var url = "https://{accountname}{projectname}/_apis/release/definitions?api-version=3.0-preview.1";

            using (HttpClient client = new HttpClient())
                var mediaTypeHeader = new MediaTypeWithQualityHeaderValue("application/json");

                var credentialBytes = Encoding.ASCII.GetBytes($"{username}:{token}");
                var encodedCredentialBytes = Convert.ToBase64String(credentialBytes);
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", encodedCredentialBytes);

                var response = await client.GetAsync(url);
                var body = await response.Content.ReadAsStringAsync();
                return body;




Comments (0)

Skip to main content