I'm working on a script for azure devops pipeline, i need my existing pat token value of Azure devops and regenerate pat token. How can i get existing pat token value and regenerate pat value by rest API
3 Answers
Rest Api does not support that: Use personal access tokens
Q: Is there a way to renew a PAT via REST API?
A: No, we don't have a REST API to renew a PAT. You can only regenerate a PAT within the user interface (UI).
Check the latest feature release:
We're happy to announce the release of new APIs to manage the lifecycle of Personal Access Tokens (PATs) in Azure DevOps. This rich set of APIs allows your team to simplify the management of the PATs they own, offering them new functionality, such as creating new personal access tokens with a desired scope and duration, and renewing or expiring existing ones.
Today, the primary way for you to manage PATs (Personal Access Tokens) is through the UI or by using a limited set of APIs intended only for Project Collection Administrators. This new API unlocks the ability for organizations to set up automation involving PATs, including setting up build pipelines or interacting with work items.
The PAT lifecycle management API is now available for organizations to use in private preview.
Please reach out to us with your use case and your Azure DevOps organization to get access to the API and documentation. We appreciate any feedback you can offer on how this API has helped your organization or can be further improved to meet your needs!
You can use the Update PAT API to update your existing PAT token. Here is a link to the PAT Update API
You can do a PUT request with CURL.
Authorization headers: Get Access token using MSAL flow for the user account you want to update the PAT token for. Use that token with Bearer Authorization in the authorization headers.
Note: You do not need to base64 encode the token. Take a look at their sample python flask app and how they use the token.
PUT request body should look like:
{
"authorizationId": "3d3aca0c-9ad3-4b07-8334-08ec8b1ddc32",
"displayName": "updated_token",
"scope": "vso.analytics",
"validTo": "2020-12-25T23:46:23.319Z",
"allOrgs": true
}
You will get a response:
{
"patToken": {
"displayName": "updated_token",
"validTo": "2020-12-25T23:46:23.32Z",
"scope": "vso.analytics",
"targetAccounts": null,
"validFrom": "2020-10-29T17:26:46.72Z",
"authorizationId": "3d3aca0c-9ad3-4b07-8334-08ec8b1ddc32",
"token": null
},
"patTokenError": "none"
}