0
votes

I'm looking into changing API gateway from another solution to Azure API management. This is for an existing app with millions of existing users / installations on end-user devices that we have no control over.

To keep existing app versions working for users, that means I need to use a custom header for the API key as well as a custom API key value.

I can change the name of the API key header in the API management portal, but I have not found a way to set up a subscription with an existing API key value instead of using a new Azure-generated API key.

Is there a way to do this? We can't force existing users to upgrade the app, and disabling API keys altogether doesn't seem like a good idea either.

2
For now I set it up as a custom header validation in the API design console, but I'm still wondering if there is a way to handle this within the subscription configuration...(?)KristoferA

2 Answers

2
votes

You can set the primary and secondary keys for a subscription by using Set-AzureRmApiManagementSubscription.

$apimContext = New-AzureRmApiManagementContext -ResourceGroupName "{resource group name}" -ServiceName "{your APIM name}"
Set-AzureRmApiManagementSubscription -Context $apimContext -SubscriptionId "{subscription id}" -PrimaryKey "{an existing API key}" -SecondaryKey "{an existing API key}" -State "Active"

You can get the subscription id by using Get-AzureRmApiManagementSubscription at first.

Please note that before you set an existing key value as the primary or secondary key, you should delete it from the original subscription/delete the subscription that has the existing key. In other words, the key is unique, you can't keep the same keys in different subscriptions.

0
votes

For those not using AzureRm (outdated) and instead Az powershell here are the commands

$apimContext = New-AzApiManagementContext -ResourceGroupName "{resource group name}" -ServiceName "{your APIM name}"

Set-AzApiManagementSubscription -Context $apimContext -SubscriptionId -"SubscriptionId" -PrimaryKey "{key1}" -SecondaryKey "{key2}" -State "Active"

To get a list of subscriptions:

Get-AzApiManagementSubscription -Context $apimContext