Rotate an API Token Without Breaking Workflows¶
An integration team must replace a KnowledgeLake API token: a scheduled rotation, a suspected leak, or an owner who left. Production workflows and functions use the token every minute. This recipe replaces it with no failed work items, including the ones already in flight.
At a glance
- Extension point API tokens, with Call External API, your own endpoint and global variables
- You need The service account that owns the current token, and the right to sign in as it; Configure API Tokens and Add Tokens for that account; Manage Secret Workflow Variables if a secret global variable holds the token.
- Teaches Finding every use of a token, overlapping old and new tokens, and the in-flight version rule.
Facts that shape the plan¶
- A token acts as the user who created it. Create the new token while signed in as the same service account, so permissions do not change.
- A token can call only the API features ticked on it, and only the ones its user holds. For work-item calls it needs Manage Work Items. For global variables it needs Manage Workflows, plus Manage Secret Global Variables for secret ones.
- The token string is shown once, when you create it.
- Old and new tokens work at the same time until you delete the old one. Deleting a token is permanent and takes effect at once.
- Work items in flight keep the workflow version, and the global variable version, from when they were submitted. They keep sending the old token.
See Authentication for how tokens work.
Set it up¶
1. Find every place the token is used¶
Write down where the old token lives:
- Secret global variables that hold the token, for example a variable that supplies the HTTP Headers of Call External API steps through the gear icon.
- Call External API steps with the token typed into HTTP Headers (
TempIdentityToken). Open each workflow and check each Call External API step. - Your own endpoints: the app setting or environment variable, for example
KnowledgeLakeApiTokenin an Azure Function app or a Lambda function, or a secret in a key vault. - Other integrations: Power Automate or Logic Apps connections, scheduled scripts, middleware, desktop tools.
2. Create the new token¶
- Sign in as the service account.
- Open Configuration > Services > API Access and select Add a Token.
- Give it a name that shows the date, for example
workflow-integration-2026-10. - Tick the same features as the old token. A missing feature is the most common cause of failures after a rotation.
- Copy the token string into your secret store at once.
Keep the old token.
3. Switch each reference¶
- Secret global variables. Edit the variable in the Workflow app, or call
V1_WorkflowAPI/SetSecretGlobalVariable. New work items read the new version. Work items already in flight keep the old version, and so the old token. - Function apps. Update the app setting. Azure restarts the app when an app setting changes. For Lambda, update the environment variable or the secret.
- Call External API headers typed into the step. Edit the step, change the header value, and save the workflow. Work items that started before the save keep the workflow version they started on, with the old header.
- Other integrations. Update each connection.
Important
Treat the token as compromised if it ever reached metadata, an event or a log. Workflow scripts can read secret global variables. If any Custom Step, Custom Event step or error message copied the token, rotate it now, delete the old one as soon as the in-flight work items pass, and remove the script that copied it.
4. Revoke the old token¶
Wait until every work item that started before the switch has passed the steps that use the token. Then, on the token list, delete the old token. Watch the workflows for an hour.
Test it¶
Before you revoke, run one test work item through each workflow that uses the token and check:
ApiResults.LastHttpStatusCodeis200on the work item, in Monitor or Insight.- The values your endpoint writes are present.
- Your function's log shows
Success: truefrom the API.
You are done when
new work items succeed with the new token, the old token is deleted, and no work item has failed with HTTP 401 for an hour.
What can go wrong¶
Watch out
- HTTP 401 ("User Is Unauthorized on endpoint ..."). The new token lacks a feature, the old token was deleted while a reference still used it, or the header name is wrong. Edit the token and tick the missing feature, or find the missed reference.
- HTTP 412 after the swap. An application error, with the details in
Messages. Check that the new token belongs to the same service account: another user can lack access to the workflow, the work item or the content type. - HTTP 422. Not a token problem: the request body does not match the action's schema.
- Work items that were already in flight fail after the revoke. They used the old workflow version or the old variable version. Revoke only after they pass the step, or restart them from Monitor after the switch.
- A function still sends the old token. It cached the token in memory. Restart the app.
- You cannot edit the secret variable. Your user lacks Manage Secret Workflow Variables. Ask an administrator.