I came across an interesting error today when running the following Azure PowerShell scripts
$ApiMgmtContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroup -ServiceName $ApimName
Set-AzApiManagementApi -Context $ApiMgmtContext -ApiId $ApiId -SubscriptionKeyQueryParamName "auth-key"
The error is as below.
Set-AzApiManagementApi : Value cannot be null.
Parameter name: source
At line:1 char:1
+ Set-AzApiManagementApi -Context $ApiMgmtContext -ApiId $ApiId -Subscr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (System.Argument...ExecuteCmdlet():ArgumentNullException) [Set-AzApiManagementApi], ArgumentNullException
+ FullyQualifiedErrorId : Value cannot be null.
Parameter name: source,Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.SetAzureApiManagementApi
After a number of trial and error tests, I found that the missing parameter is '-Protocols'.
So the final script that worked was:
$ApiMgmtContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroup -ServiceName $ApimName
Set-AzApiManagementApi -Context $ApiMgmtContext -ApiId $ApiId -Protocols @('https') -SubscriptionKeyQueryParamName "auth-key"
What interesting is that the documentation at https://docs.microsoft.com/en-us/powershell/module/az.apimanagement/set-azapimanagementapi?view=azps-3.7.0 does not mention -Protocol is a required parameter.