Closed valiorik closed 5 years ago
@valiorik orik Can you verify whether you are using Az cmdlets, or AzureRm cmdlets for this? If you have executed Enable-AzureRmAlias, then the above would be using Az cmdlets, otherwise, it would be using your installed AzureRm cmdlets.
Note that, if you don't want these cmdlets installed side-by-side, you cna use Uninstall-AzureRm to remove old versions of AzureRm cmdlets.
@markcowl was running Az cmdlets. Had Enable-AzureRmAlias at the begging of the script and it didn't got to the code snippet I have posted.
To double check removed AzureRm modules by running Uninstall-AzureRm and restarting the machine.
PsApiManagementApi object I am getting after importing or creating new API looks like this:
[DBG]: PS C:\> $api
ApiId : xxx
Name : xxx
Description : xxx
ServiceUrl : xxx
Path : xxx
ApiType : http
Protocols : {Https}
AuthorizationServerId :
AuthorizationScope :
SubscriptionKeyHeaderName : Ocp-Apim-Subscription-Key
SubscriptionKeyQueryParamName : subscription-key
ApiRevision : 1
ApiVersion :
IsCurrent : True
IsOnline : False
Id : xxx
ResourceGroupName : xxx
ServiceName : xxx
ApiVersion property can be set, but calling Set-AzureRmApiManagementApi -InputObject $api
produces error "Can't set VersionName when ApiVersionSetId is not set.". I am able to create ApiVersionSet in same ApiManagement instance, but have no way to set it for the ApiManagementApi.
Ideally Import-AzureRmApiManagementApi and New-AzureRmApiManagementApi should take ApiVersionSetId and ApiVersion as optional parameter to mimic portal behaviour and allow to create new Api with versioning from the begging.
@solankisamir Can you take a look at this issue?
Are there any plans to add what @valiorik suggested in Import-AzureRmApiManagementApi?
Yes, we are fixing a bug in the service side and then add support. ETA 1 month
released - v2.4.0-July2019
I still get the issue after updating to the latest Az Module. Running my script twice solves it.
New-AzApiManagementApi : Error Code: ValidationError Error Message: One or more fields contain incorrect values: Request Id: 24914252-d2fc-40ff-a5d4-309860b0259f Error Details: [Code= ValidationError, Message= Can't set VersionName when ApiVersionSetId is not set., Target= ApiVersion] At somefile.ps1:29 char:5 + New-AzApiManagementApi -Context $ApiMgmtContext -ApiId $ApiId -Na ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (Microsoft.Azure...ExecuteCmdlet():ErrorResponseException) [New-AzApiManageme ntApi], Exception + FullyQualifiedErrorId : Operation returned an invalid status code 'BadRequest',Microsoft.Azure.Commands.ApiManage ment.ServiceManagement.Commands.NewAzureApiManagementApi
Description
Powershell command Import-AzureRmApiManagementApi does not allow to set up the version of imported APIs.
Script/Steps for Reproduction
In Azure web portal I can choose a version of new API during its creation (ticking "Version this API?") and it will build a path just like I want it:
https://xxx.azure-api.net/1.0/
So in future new versions will fall to same format:
https://xxx.azure-api.net/1.1/ https://xxx.azure-api.net/1.2/ https://xxx.azure-api.net/2.0/
It would be ace to be able to do the same with PowerShell command. My deployments are fully automated, so configuring in Azure portal is out of the question.
As a workarround I have tried to import API without a version, get back PsApiManagementApi object and set it's version by calling
But getting the error:
Sadly PsApiManagementApi does not expose ApiVersionSetId parameter. So got stuck with this workarround as well.
Any ideas please?
Module Version
Environment Data
Debug Output