-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
Description
When creating a new API in APIM, the serviceUrl property is optional (https://learn.microsoft.com/en-us/rest/api/apimanagement/apis/create-or-update?view=rest-apimanagement-2024-05-01&tabs=HTTP).
But when creating a new API in APIM via New-AzApiManagementApi, the cmdlet is stating that the ServiceUrl is required, when it should be optional. (https://learn.microsoft.com/en-us/powershell/module/az.apimanagement/new-azapimanagementapi?view=azps-15.4.0#-serviceurl).
This is very easy to reproduce.
$ctx = New-AzApiManagementContext -ResourceGroupName "<rg-name>"
-ServiceName ""
New-AzApiManagementApi -Context $ctx
-ApiId "serviceUrltest" -Name "serviceUrltest"
-Path "serviceUrltest" `
-Protocols Http
PowerShell prompts:
cmdlet New-AzApiManagementApi at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
ServiceUrl:
This confirms the cmdlet enforces ServiceUrl client‑side.
This is not coming from ARM.
The same behavior is present if you try to create an APIM API Revision (which uses the same command).
Tested on AzurePowershell versions 14.6.0 and 15.2.0, both using Az.ApiManagement 4.1.0 (https://www.powershellgallery.com/packages/Az.ApiManagement/4.1.0).
Issue script & Debug output
cmdlet New-AzApiManagementApi at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
ServiceUrl:
New-AzApiManagementApi: Cannot validate argument on parameter 'ServiceUrl'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.Environment data
Name Value
---- -----
PSVersion 7.5.4
PSEdition Core
GitCommitId 7.5.4
OS Microsoft Azure Linux 3.0
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Module versions
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 5.3.2 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
Script 4.1.0 Az.ApiManagement {Add-AzApiManagementApiToGateway, Add-AzApiManagementApiToProduct, Add-AzApiManagementProductToGroup, Add-AzApiManagementRegion…}
Script 11.2.0 Az.Compute {Add-AzGalleryInVMAccessControlProfileVersionRulesIdentity, Add-AzGalleryInVMAccessControlProfileVersionRulesPrivilege, Add-AzGalleryInVMAccessControlProfileVersionRulesRole, Add-AzGalleryInVMAccessContr…
Script 7.24.1 Az.Network {Add-AzApplicationGatewayAuthenticationCertificate, Add-AzApplicationGatewayBackendAddressPool, Add-AzApplicationGatewayBackendHttpSetting, Add-AzApplicationGatewayBackendSetting…}
Script 9.0.0 Az.Resources {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssignment, Get-AzDeployment…}
Script 9.5.0 Az.Storage {Add-AzRmStorageContainerLegalHold, Add-AzStorageAccountManagementPolicyAction, Add-AzStorageAccountNetworkRule, Close-AzStorageFileHandle…}
Script 1.1.3 Az.Tools.Predictor {Disable-AzPredictor, Enable-AzPredictor, Open-AzPredictorSurvey, Send-AzPredictorRating}
Script 0.0.0.10 AzureAD.Standard.Preview {Add-AzureADApplicationOwner, Add-AzureADDeviceRegisteredOwner, Add-AzureADDeviceRegisteredUser, Add-AzureADDirectoryRoleMember…}
Script 0.9.3 AzurePSDriveError output
HistoryId: 3
Message : Cannot validate argument on parameter 'ServiceUrl'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
StackTrace : at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
at System.Management.Automation.CmdletParameterBinderController.BindParameter(CommandParameterInternal argument, MergedCompiledCommandParameter parameter, ParameterBindingFlags flags)
at System.Management.Automation.CmdletParameterBinderController.BindParameter(UInt32 parameterSets, CommandParameterInternal argument, MergedCompiledCommandParameter parameter, ParameterBindingFlags flags)
at System.Management.Automation.ParameterBinderController.BindParameter(CommandParameterInternal argument, ParameterBindingFlags flags)
at System.Management.Automation.CmdletParameterBinderController.HandleUnboundMandatoryParameters(Int32 validParameterSetCount, Boolean processMissingMandatory, Boolean promptForMandatory, Boolean isPipelineInputExpected, Collection`1&
missingMandatoryParameters)
at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection`1 arguments)
at System.Management.Automation.CommandProcessor.BindCommandLineParameters()
at System.Management.Automation.CommandProcessor.Prepare(IDictionary psDefaultParameterValues)
at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)
at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
--- End of stack trace from previous location ---
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
Exception : System.Management.Automation.ParameterBindingValidationException
InvocationInfo : {New-AzApiManagementApi}
Line : New-AzApiManagementApi -Context $ctx -ApiId "serviceUrltest" -Name "serviceUrltest" -Path "serviceUrltest" -Protocols Http
Position : At line:1 char:1
+ New-AzApiManagementApi -Context $ctx -ApiId "serviceUrltest" -Name "s …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 3
Message : The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
StackTrace : at System.Management.Automation.ValidateNotNullOrAttributeBase.Validate(Object arguments, EngineIntrinsics engineIntrinsics)
at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
Exception : System.Management.Automation.ValidationMetadataException
InvocationInfo : {New-AzApiManagementApi}
Line : New-AzApiManagementApi -Context $ctx -ApiId "serviceUrltest" -Name "serviceUrltest" -Path "serviceUrltest" -Protocols Http
Position : At line:1 char:1
+ New-AzApiManagementApi -Context $ctx -ApiId "serviceUrltest" -Name "s …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 3