Skip to content

Commit 68db0ec

Browse files
Merge pull request #8020 from MicrosoftDocs/users/chcomley/uuf-420769
UUF - Update REST API samples
2 parents 629c9b5 + 7f71e8e commit 68db0ec

File tree

1 file changed

+52
-14
lines changed

1 file changed

+52
-14
lines changed

docs/integrate/get-started/rest/samples.md

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
title: REST API samples
33
description: REST API samples for Azure DevOps, including personal access tokens (PATs).
44
ms.assetid: 9E17A266-051F-403F-A285-7F21D9CC52F0
5+
ai-usage: ai-assisted
56
ms.subservice: azure-devops-ecosystem
67
ms.topic: conceptual
78
ms.custom: devx-track-dotnet
89
monikerRange: '<= azure-devops'
910
ms.author: chcomley
1011
author: chcomley
11-
ms.date: 03/21/2025
12+
ms.date: 06/12/2025
1213
---
1314

1415
# REST API samples for Azure DevOps
@@ -17,26 +18,30 @@ ms.date: 03/21/2025
1718

1819
Most samples in this article use personal access tokens (PATs). While PATs are a compact example for authentication, we don't recommend using them for production applications. There are many other authentication mechanisms available, including Microsoft Authentication Library, OAuth, and Session tokens. For more information to gauge which is best suited for your scenario, see [Authentication guidance](../authentication/authentication-guidance.md).
1920

20-
For more information, see [Azure DevOps Services REST API Reference](/rest/api/azure/devops/?view=azure-devops-rest-7.2&preserve-view=true) and [Get started with REST APIs](../../how-to/call-rest-api.md).
21+
For more information, see [Azure DevOps REST API Reference](/rest/api/azure/devops/?view=azure-devops-rest-7.2&preserve-view=true) and [Get started with REST APIs](../../how-to/call-rest-api.md).
2122

22-
## Personal access tokens
23+
## Authentication
2324

24-
Authenticate with Azure DevOps when you use the REST APIs or .NET Libraries.
25+
Authenticate with Azure DevOps when using the REST APIs or .NET Libraries by following these steps:
2526

26-
Get started with these samples and [create a PAT](../../../organizations/accounts/use-personal-access-tokens-to-authenticate.md).
27+
- **Create a PAT:**
28+
Start with these samples and [create a personal access token (PAT)](../../../organizations/accounts/use-personal-access-tokens-to-authenticate.md).
2729

28-
> [!NOTE]
29-
> We don't recommend using PATs. For more secure authentication mechanisms, see [Authentication guidance](../authentication/authentication-guidance.md).
30+
[!INCLUDE [use-microsoft-entra-reduce-pats](../../../includes/use-microsoft-entra-reduce-pats.md)]
3031

31-
To provide the PAT through an HTTP header, first convert it to a Base64 string. The following example shows how to convert to Base64 using C#. You can provide the resulting string as an HTTP header in the following format:
32+
- **Use Basic Authentication with a PAT:**
33+
1. Convert your PAT to a Base64-encoded string in the format `username:PAT` (the username can be empty).
34+
2. Add the encoded string to the `Authorization` HTTP header.
3235

33-
``
34-
Authorization: Basic BASE64USERNAME:PATSTRING
35-
``
36+
**Example using Basic Authentication with curl:**
3637

37-
## REST API
38+
```bash
39+
curl -u :{yourPAT} https://dev.azure.com/{organization}/_apis/projects?api-version=7.2-preview.1
40+
```
3841

39-
See the following example of getting a list of projects for your organization via REST API.
42+
## GET request samples
43+
44+
The following C# and curl requests return a JSON response containing the list of all projects in a specified organization:
4045

4146
```cs
4247
using System.Net.Http;
@@ -69,7 +74,40 @@ using (var client = new HttpClient())
6974
//var value = response.Content.ReadAsStringAsync().Result;
7075
}
7176
}
77+
```
78+
79+
80+
```curl
81+
-u username:PAT https://dev.azure.com/{organization}/_apis/projects?api-version=6.0
82+
```
83+
84+
## POST request sample
85+
86+
The following curl request creates a new work item of the "Task" type in a specified project:
87+
88+
```curl
89+
-u username:PAT -X POST -H "Content-Type: application/json" \
90+
-d '{"fields": {"System.Title": "New Work Item"}}' \
91+
https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/$Task?api-version=6.0
92+
```
93+
94+
## PUT request sample
95+
96+
The following curl request updates an existing work item by changing its state to "In Progress":
97+
98+
```curl
99+
-u username:PAT -X PATCH -H "Content-Type: application/json-patch+json" \
100+
-d '[{"op": "add", "path": "/fields/System.State", "value": "In Progress"}]' \
101+
https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/{id}?api-version=6.0
102+
```
103+
104+
## DELETE request sample
105+
106+
The following curl request deletes an existing work item from a specified project:
72107

108+
```curl
109+
-u username:PAT -X DELETE \
110+
https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/{id}?api-version=6.0
73111
```
74112

75113
## .NET Client Libraries
@@ -79,7 +117,7 @@ Here, we're using two of the .NET Client Libraries. Make sure you reference the
79117
- [Microsoft.TeamFoundationServer.Client](https://www.nuget.org/packages/Microsoft.TeamFoundationServer.Client/)
80118
- [Microsoft.Visual Studio.Services.Client](https://www.nuget.org/packages/Microsoft.VisualStudio.Services.Client/)
81119

82-
See the following example of getting a list of projects for your organization via .NET Client Libraries.
120+
The following example gets a list of projects for your organization via .NET Client Libraries:
83121

84122
```cs
85123
using Microsoft.TeamFoundation.Core.WebApi;

0 commit comments

Comments
 (0)