Forum Discussion
How to fetch the user in azure devOps using API
I am using the azure board API. I want to know is there any API to fetch the user which is associated with the PAT token provided. Basically, want to verify if a valid user exists for associated PAT or if the PAT is valid or not.
- balasubramanimIron Contributor
To fetch the user associated with a PAT (Personal Access Token) in Azure DevOps, you can use the Profile API. please try the following API's
Endpoint - GET https://app.vssps.visualstudio.com/_apis/profile/profiles/me?api-version=7.1-preview.1
Authorization Header: Encode your PAT as :PAT in Base64 and include it:
Authorization: Basic BASE64_ENCODED_PATExample using curl
curl -X GET \
-H "Authorization: Basic $(echo -n :YOUR_PAT | base64)" \
https://app.vssps.visualstudio.com/_apis/profile/profiles/me?api-version=7.1-preview.1Response: If valid, you'll get user details like displayName and emailAddress. If invalid, you'll get a 401 Unauthorized error
Try this:
- Get the PAT details: Use the GET method to retrieve details about the PAT. This will help you verify if the PAT is valid.
GET https://dev.azure.com/{organization}/_apis/tokens/pats/{patId}?api-version=7.1-preview
- Check the response: The response will include details about the PAT, such as its validity and the associated user. If the PAT is valid, you will get the user information in the response.
- Get the PAT details: Use the GET method to retrieve details about the PAT. This will help you verify if the PAT is valid.