Archive

Posts Tagged ‘REST API’

Access VSO Work Items in Postman, by using Azure DevOps REST APIs, using PAT (Personal Access Token) authentication

March 4, 2021 2 comments

 
Here in this post we will try to access VSO Work Items from Postman tool by using Azure DevOps REST APIs. To access and authenticate into Azure DevOps we will first create PAT (Personal Access Token) and then use it in the Postman tool.
 

Create Token in Azure DevOps portal:

 

1. Go to https://dev.azure.com/{YourOrg}/. On the top-right corner of the browser click on “User Settings” icon, and select “Personal access token” option from the drop down.


 

2. Now on the settings page click on the + icon to create a new Token, provide a new Name and Expiry Date of the Token, and scroll down.


 

3. At the bottom of the page you will see “Work Items” section, just select the “Read & write” check box, and click Create.


 

4. Now your Token is created, just copy it by clicking on the Copy button and save it somewhere securely. Otherwise you won’t be seeing it again on the portal for security reasons.


 

Using Postman to access VSO Work Items:

 

5. Download & Install Postman from here [link]
 

6. Open Postman tool, create a new Collection and add a new Request of type GET.

Populate following URL: https://dev.azure.com/{{YourOrg}}/{{YourProject}}/_apis/wit/workitems/
{{workitemId}}?api-version=6.0

Auth Tab:
  — Type = “Basic Auth”
    — UserName: {{PAT name}}
    — Password: {{Copied PAT secret from Azure DevOps portal}}


 

6. Now clicking on Send button will return you the Response with all the VSO Work Item attributes and details.


Advertisement

REST API, PATCH request error, Postman – Valid content types for this method are: application/json-patch+json

March 2, 2021 Leave a comment

 
I was trying to use the Azure DevOps REST APIs to get some details of VSO WorkItems by using Postman tool. Doing GET-Request was not a problem and it returned the expected JSON response body with all attributes and details.

But when I tried to update the same VSO WorkItem by using POST request it resulted in below error:

{
“$id”: “1”,
“innerException”: null,
“message”: “The request indicated a Content-Type of \”application/json\” for method type \”PATCH\” which is not supported. Valid content types for this method are: application/json-patch+json.“,
“typeName”: “Microsoft.VisualStudio.Services.WebApi.VssRequestContentTypeNotSupportedException, Microsoft.VisualStudio.Services.WebApi”,
“typeKey”: “VssRequestContentTypeNotSupportedException“,
“errorCode”: 0,
“eventId”: 3000
}

 

Solution:

As the above error mentions to use “application/json-patch+json” as the Content Type, so the same has to be added under the Headers tab as Key Value, like:

KEY: Content-Type
VALUE: application/json-patch+json


 

If you observe similar error while working with PowerShell, you’ve to pass the same value with ContentType parameter in the Invoke-RestMethod command:

Invoke-RestMethod -Method Post -Uri $theUri -Headers $theHeader -ContentType “application/json-patch+json” -Body $theBody