Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,908 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
How do I find the user associated with a subscription key?
I understand I can find Sub key associated with a user. But is there a way to find User associated with a specific sub key?
@Martin Kallukalam Here is sample script where it checks all the apim instances within your subscription to identify the respective subscription Id and user who owns it. Kindly fill in the respective values where "xxx" is mentioned.
try {
"Logging in to Azure..."
Connect-AzAccount -Tenant "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"
}
catch {
Write-Error -Message $_.Exception
throw $_.Exception
}
$subscriptions = Get-AzSubscription -SubscriptionId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"
Set-AzContext -Subscription $subscriptions[0]
$apiminstances = Get-AzApiManagement
foreach ( $apim in $apiminstances) {
$apimContext = New-AzApiManagementContext -ResourceGroupName $apim.ResourceGroupName -ServiceName $apim.Name
$sId = Get-AzApiManagementSubscription -Context $apimContext
foreach ($s in $sId) {
$subKey = Get-AzApiManagementSubscriptionKey -Context $apimContext -SubscriptionId $s.SubscriptionId
if ($subKey.PrimaryKey -eq "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -or $subKey.SecondaryKey -eq "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") {
$subtemp = Get-AzApiManagementSubscription -context $apimContext -SubscriptionId $s.SubscriptionId
$user = Get-AzApiManagementUser -Context $apimContext -UserId $subtemp.UserId
Write-Host "Subscription ID: " + $s.SubscriptionId + " User ID: " + $user.Id + " User Email: " + $user.Email
}
}
}