Alert API key owners about the API key expiration within x days
This article contains additional information on the "Alerts API key owners about API key expiring within x days" template. You can find this template in the template picker when creating new automation.
This template will send an alert email to API key owners with a list of API keys that are expiring within x days or that have expired or been revoked. It can also alert all tenant admins via email with a list of API keys that have been orphaned by the deletion of their owner's account.
For example, if we want to know the API keys that are expired/have been revoked and are expiring within 10 days, we can use this template which retrieves the information and sends an email to the respective users/tenant admins.
Steps to set up the values in the template:
Set the value for the variable APIKeyExpiresWithinDays which specifies the API keys that will be expiring or have expired/have been revoked for 'x' num of days. Where x is a number set in this variable.
Set the value for the variable EmailTenantAdmins which allows to Email all tenant admins the list of API keys orphaned by the deletion of their owner's account. The value can be Yes/No.
Retrieve all the users using the List Users block and store them in the variable.
Retrieve all the API keys using the Raw API List Request block and store them in the variable named API keys.
Loop over each API key in the APIKeys object and check if the API key is expiring within the set number of days ("APIKeyExpiresWithinDays").
If the API keys are found, then store them in the variable UserAPIKeys.
Retrieve the tenant information using theGet Current Tenant Infoblock and store the tenant URL in the tenantURL variable.
Loop over the UserAPIKeys and check if the user is tenantAdmin and pick the username and user email of the API key owner to send an email.
Construct the email body using the above information and send an email to the owner of the API key.