Skip to content

Instantly share code, notes, and snippets.

@jasonroy7dct
Created October 8, 2020 11:03
Show Gist options
  • Save jasonroy7dct/36683459e4c546bae1e3e6b37769ca6c to your computer and use it in GitHub Desktop.
Save jasonroy7dct/36683459e4c546bae1e3e6b37769ca6c to your computer and use it in GitHub Desktop.
# Azure DevOps REST API Reference
> **Use Azure DevOps REST API for listing, creating and updating work items.**
- **Get in to Azure DevOps**
1. Log in : [https://dev.azure.com/](https://dev.azure.com/)
- ***Project > Boards > Work items***
![Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled.png](Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled.png)
2. No Work items now, go ahead to create work items by using API
![Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/_2020-10-08_5.36.10.png](Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/_2020-10-08_5.36.10.png)
3. In order to access your organization or team project, you have to set Personal access tokens(PAT) for the Authentication
- ***User Settings > Personal access tokens***
![Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled%201.png](Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled%201.png)
4. Create a new personal access token
- ***New Token > Set Name > Define the Scopes (Full access or Custom defined)***
![Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled%202.png](Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled%202.png)
5. Remember to copy the token and keep it
![Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/_2020-10-08_6.06.04.png](Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/_2020-10-08_6.06.04.png)
- **Enter Postman to access the Azure DevOps REST API**
1. Create a New Request
![Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled%203.png](Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled%203.png)
2. Set up the Authorization, use the Personal access tokens(PAT) to access it.
- ***Authorization > TYPE > Basic Auth***
- ***Username: (Default Blank) , Password: {Personal access tokens}***
![Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled%204.png](Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled%204.png)
- **Create Work Items**
1. Creates a single work item:
```
**POST [https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/${type}?api-version=5.1](https://dev.azure.com/%7Borganization%7D/%7Bproject%7D/_apis/wit/workitems/$%7Btype%7D?api-version=5.1)**
```
- **{organization} The name of the Azure DevOps organization.**
- **{project} Project ID or project name**
- **{type} The work item type of the work item to create**
- **{api-version} Version of the API to use**
Example:
```
**POST [https://dev.azure.com/16th-JasonHsieh/Cigna2020/_apis/wit/workitems/$task?api-version=5.1](https://dev.azure.com/16th-JasonHsieh/Cigna2020/_apis/wit/workitems/$task?api-version=5.1)**
```
![Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled%205.png](Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled%205.png)
2. For creating work items, you have to send body data with requests.
- ***Add "Content-Type" to Headers***
- ***Key: Content-Type***
- ***Value: application/json-patch+json***
![Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled%206.png](Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled%206.png)
3. Add Request Body to Body in JSON format
![Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled%207.png](Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled%207.png)
```json
[
{
"op": "add",
"path": "/fields/System.Title",
"from": null,
"value": "Sample task"
}
]
```
4. Send and test it, receive 200 OK
![Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled%208.png](Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled%208.png)
5. Go to Azure DevOps to check the result, task created
![Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled%209.png](Azure%20DevOps%20REST%20API%20Reference%20b7c10d16aa98485ab0a18e4f3cbcede0/Untitled%209.png)
- Microsoft Docs
[Work Items (Azure DevOps Work Item Tracking)](https://docs.microsoft.com/en-us/rest/api/vsts/wit/work%20items?view=azure-devops-rest-5.0&viewFallbackFrom=azure-devops)
@jasonroy7dct
Copy link
Author

ff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment