Skip to content

Commit ee48acd

Browse files
committed
added basic REST samples that don't require client or lang - UUF
1 parent a42cb93 commit ee48acd

File tree

1 file changed

+55
-14
lines changed

1 file changed

+55
-14
lines changed

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

Lines changed: 55 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/10/2025
1213
---
1314

1415
# REST API samples for Azure DevOps
@@ -17,26 +18,31 @@ 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+
- **Preferred Microsoft Entra authentication:**
31+
[!INCLUDE [use-microsoft-entra-reduce-pats](../../../includes/use-microsoft-entra-reduce-pats.md)]
3032

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:
33+
- **Use Basic Authentication with a PAT:**
34+
1. Convert your PAT to a Base64-encoded string in the format `username:PAT` (the username can be empty).
35+
2. Add the encoded string to the `Authorization` HTTP header.
3236

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

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

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

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

107+
The following curl request deletes an existing work item from a specified project:
108+
109+
```curl
110+
-u username:PAT -X DELETE \
111+
https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/{id}?api-version=6.0
73112
```
74113

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

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

84123
```cs
85124
using Microsoft.TeamFoundation.Core.WebApi;
@@ -98,6 +137,8 @@ using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(uri, credenti
98137

99138
```
100139

140+
## Error handling
141+
101142
## FAQs
102143

103144
<!-- BEGINSECTION class="md-qanda" -->

0 commit comments

Comments
 (0)