Forum Discussion

surendra-p's avatar
surendra-p
Copper Contributor
Dec 09, 2024

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.

  • surendra-p 

    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_PAT

    Example 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.1

    Response: If valid, you'll get user details like displayName and emailAddress. If invalid, you'll get a 401 Unauthorized error

  • Try this:

     

    1. 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

       

      Replace {organization} with your Azure DevOps organization name and {patId} with the ID of the PAT you want to verify.
    2. 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.

Resources