Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import-AzApiManagementApi #9336

Open
Danlewis3 opened this issue May 31, 2019 · 9 comments

Comments

@Danlewis3
Copy link

@Danlewis3 Danlewis3 commented May 31, 2019

Importing an OpenApi or Swagger definition and when specifing a ServiceUrl it will not apply this URL.

when creating a new api using New-AzApiManagementApi the URL is set but on importing it will not set

Steps to reproduce

Import-AzApiManagementApi -Context $ApiMgmtContext -ServiceUrl 'PATH HERE' -SpecificationFormat "OpenApi" -SpecificationPath $output -Path "testapi112111" -ApiId $ID 

Environment data

Name                           Value                                                                                                                                                                             
----                           -----                                                                                                                                                                             
PSVersion                      5.1.14409.1018                                                                                                                                                                    
PSEdition                      Desktop                                                                                                                                                                           
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                           
BuildVersion                   10.0.14409.1018                                                                                                                                                                   
CLRVersion                     4.0.30319.42000                                                                                                                                                                   
WSManStackVersion              3.0                                                                                                                                                                               
PSRemotingProtocolVersion      2.3                                                                                                                                                                               
SerializationVersion           1.1.0.1   

Module versions

ModuleType Version    Name                                ExportedCommands                                                                                                                                       
---------- -------    ----                                ----------------                                                                                                                                       
Script     1.0.3      PSYaml                              {ConvertFrom-Yaml, ConvertTo-Yaml, Convert-YamlToJson}                                                                                                 


    Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands                                                                                                                                       
---------- -------    ----                                ----------------                                                                                                                                       
Script     1.5.2      Az.Accounts                         {Disable-AzDataCollection, Disable-AzContextAutosave, Enable-AzDataCollection, Enable-AzContextAutosave...}                                            
Script     1.0.1      Az.Aks                              {Get-AzAks, New-AzAks, Remove-AzAks, Import-AzAksCredential...}                                                                                        
Script     1.1.0      Az.AnalysisServices                 {Resume-AzAnalysisServicesServer, Suspend-AzAnalysisServicesServer, Get-AzAnalysisServicesServer, Remove-AzAnalysisServicesServer...}                  
Script     1.1.0      Az.ApiManagement                    {Add-AzApiManagementApiToProduct, Add-AzApiManagementProductToGroup, Add-AzApiManagementRegion, Add-AzApiManagementUserToGroup...}                     
Script     1.0.0      Az.ApplicationInsights              {Get-AzApplicationInsights, New-AzApplicationInsights, Remove-AzApplicationInsights, Set-AzApplicationInsightsPricingPlan...}                          
Script     1.2.2      Az.Automation                       {Get-AzAutomationHybridWorkerGroup, Remove-AzAutomationHybridWorkerGroup, Get-AzAutomationJobOutputRecord, Import-AzAutomationDscNodeConfiguration...} 
Script     1.1.0      Az.Batch                            {Remove-AzBatchAccount, Get-AzBatchAccount, Get-AzBatchAccountKey, New-AzBatchAccount...}                                                              
Script     1.0.0      Az.Billing                          {Get-AzBillingInvoice, Get-AzBillingPeriod, Get-AzEnrollmentAccount, Get-AzConsumptionBudget...}                                                       
Script     1.2.0      Az.Cdn                              {Get-AzCdnProfile, Get-AzCdnProfileSsoUrl, New-AzCdnProfile, Remove-AzCdnProfile...}                                                                   
Script     1.1.1      Az.CognitiveServices                {Get-AzCognitiveServicesAccount, Get-AzCognitiveServicesAccountKey, Get-AzCognitiveServicesAccountSku, Get-AzCognitiveServicesAccountType...}          
Script     2.1.0      Az.Compute                          {Remove-AzAvailabilitySet, Get-AzAvailabilitySet, New-AzAvailabilitySet, Update-AzAvailabilitySet...}                                                  
Script     1.0.1      Az.ContainerInstance                {New-AzContainerGroup, Get-AzContainerGroup, Remove-AzContainerGroup, Get-AzContainerInstanceLog}                                                      
Script     1.0.1      Az.ContainerRegistry                {New-AzContainerRegistry, Get-AzContainerRegistry, Update-AzContainerRegistry, Remove-AzContainerRegistry...}                                          
Script     1.1.1      Az.DataFactory                      {Set-AzDataFactoryV2, Update-AzDataFactoryV2, Get-AzDataFactoryV2, Remove-AzDataFactoryV2...}                                                          
Script     1.0.0      Az.DataLakeAnalytics                {Get-AzDataLakeAnalyticsDataSource, New-AzDataLakeAnalyticsCatalogCredential, Remove-AzDataLakeAnalyticsCatalogCredential, Set-AzDataLakeAnalyticsCa...
Script     1.2.1      Az.DataLakeStore                    {Get-AzDataLakeStoreTrustedIdProvider, Remove-AzDataLakeStoreTrustedIdProvider, Remove-AzDataLakeStoreFirewallRule, Set-AzDataLakeStoreTrustedIdProv...
Script     1.0.0      Az.DeploymentManager                {Get-AzDeploymentManagerArtifactSource, New-AzDeploymentManagerArtifactSource, Set-AzDeploymentManagerArtifactSource, Remove-AzDeploymentManagerArti...
Script     1.0.0      Az.DevTestLabs                      {Get-AzDtlAllowedVMSizesPolicy, Get-AzDtlAutoShutdownPolicy, Get-AzDtlAutoStartPolicy, Get-AzDtlVMsPerLabPolicy...}                                    
Script     1.1.0      Az.Dns                              {Get-AzDnsRecordSet, New-AzDnsRecordConfig, Remove-AzDnsRecordSet, Set-AzDnsRecordSet...}                                                              
Script     1.1.1      Az.EventGrid                        {New-AzEventGridTopic, Get-AzEventGridTopic, Set-AzEventGridTopic, New-AzEventGridTopicKey...}                                                         
Script     1.1.0      Az.EventHub                         {New-AzEventHubNamespace, Get-AzEventHubNamespace, Set-AzEventHubNamespace, Remove-AzEventHubNamespace...}                                             
Script     1.0.0      Az.FrontDoor                        {New-AzFrontDoor, Get-AzFrontDoor, Set-AzFrontDoor, Remove-AzFrontDoor...}                                                                             
Script     2.0.0      Az.HDInsight                        {Get-AzHDInsightJob, New-AzHDInsightSqoopJobDefinition, Wait-AzHDInsightJob, New-AzHDInsightStreamingMapReduceJobDefinition...}                        
Script     1.1.0      Az.IotHub                           {Add-AzIotHubKey, Get-AzIotHubEventHubConsumerGroup, Get-AzIotHubConnectionString, Get-AzIotHubJob...}                                                 
Script     1.2.0      Az.KeyVault                         {Add-AzKeyVaultCertificate, Update-AzKeyVaultCertificate, Stop-AzKeyVaultCertificateOperation, Get-AzKeyVaultCertificateOperation...}                  
Script     1.2.1      Az.LogicApp                         {Get-AzIntegrationAccountAgreement, Get-AzIntegrationAccountAssembly, Get-AzIntegrationAccountBatchConfiguration, Get-AzIntegrationAccountCallbackUr...
Script     1.1.0      Az.MachineLearning                  {Move-AzMlCommitmentAssociation, Get-AzMlCommitmentAssociation, Get-AzMlCommitmentPlanUsageHistory, Remove-AzMlCommitmentPlan...}                      
Script     1.0.0      Az.MarketplaceOrdering              {Get-AzMarketplaceTerms, Set-AzMarketplaceTerms}                                                                                                       
Script     1.1.0      Az.Media                            {Sync-AzMediaServiceStorageKey, Set-AzMediaServiceKey, Get-AzMediaServiceKey, Get-AzMediaServiceNameAvailability...}                                   
Script     1.2.1      Az.Monitor                          {Get-AzMetricDefinition, Get-AzMetric, Remove-AzLogProfile, Get-AzLogProfile...}                                                                       
Script     1.8.1      Az.Network                          {Add-AzApplicationGatewayAuthenticationCertificate, Get-AzApplicationGatewayAuthenticationCertificate, New-AzApplicationGatewayAuthenticationCertifi...
Script     1.1.0      Az.NotificationHubs                 {Get-AzNotificationHub, Get-AzNotificationHubAuthorizationRule, Get-AzNotificationHubListKey, Get-AzNotificationHubPNSCredential...}                   
Script     1.2.0      Az.OperationalInsights              {New-AzOperationalInsightsAzureActivityLogDataSource, New-AzOperationalInsightsCustomLogDataSource, Disable-AzOperationalInsightsLinuxCustomLogColle...
Script     1.1.0      Az.PolicyInsights                   {Get-AzPolicyEvent, Get-AzPolicyState, Get-AzPolicyStateSummary, Get-AzPolicyRemediation...}                                                           
Script     1.1.0      Az.PowerBIEmbedded                  {Remove-AzPowerBIWorkspaceCollection, Get-AzPowerBIWorkspaceCollection, Get-AzPowerBIWorkspaceCollectionAccessKey, Get-AzPowerBIWorkspace...}          
Script     1.4.0      Az.RecoveryServices                 {Get-AzRecoveryServicesBackupProperty, Get-AzRecoveryServicesVault, Get-AzRecoveryServicesVaultSettingsFile, New-AzRecoveryServicesVault...}           
Script     1.1.0      Az.RedisCache                       {Remove-AzRedisCachePatchSchedule, New-AzRedisCacheScheduleEntry, Get-AzRedisCachePatchSchedule, New-AzRedisCachePatchSchedule...}                     
Script     1.0.1      Az.Relay                            {New-AzRelayNamespace, Get-AzRelayNamespace, Set-AzRelayNamespace, Remove-AzRelayNamespace...}                                                         
Script     1.4.0      Az.Resources                        {Get-AzProviderOperation, Remove-AzRoleAssignment, Get-AzRoleAssignment, New-AzRoleAssignment...}                                                      
Script     1.1.0      Az.ServiceBus                       {New-AzServiceBusNamespace, Get-AzServiceBusNamespace, Set-AzServiceBusNamespace, Remove-AzServiceBusNamespace...}                                     
Script     1.0.1      Az.ServiceFabric                    {Add-AzServiceFabricApplicationCertificate, Add-AzServiceFabricClientCertificate, Add-AzServiceFabricClusterCertificate, Add-AzServiceFabricNode...}   
Script     1.0.2      Az.SignalR                          {New-AzSignalR, Get-AzSignalR, Get-AzSignalRKey, New-AzSignalRKey...}                                                                                  
Script     1.10.0     Az.Sql                              {Get-AzSqlDatabaseTransparentDataEncryption, Get-AzSqlDatabaseTransparentDataEncryptionActivity, Set-AzSqlDatabaseTransparentDataEncryption, Get-AzS...
Script     1.3.0      Az.Storage                          {Get-AzStorageAccount, Get-AzStorageAccountKey, New-AzStorageAccount, New-AzStorageAccountKey...}                                                      
Script     1.0.0      Az.StreamAnalytics                  {Get-AzStreamAnalyticsFunction, Get-AzStreamAnalyticsDefaultFunctionDefinition, New-AzStreamAnalyticsFunction, Remove-AzStreamAnalyticsFunction...}    
Script     1.0.1      Az.TrafficManager                   {Add-AzTrafficManagerCustomHeaderToEndpoint, Remove-AzTrafficManagerCustomHeaderFromEndpoint, Add-AzTrafficManagerCustomHeaderToProfile, Remove-AzTr...
Script     1.2.1      Az.Websites                         {Get-AzAppServicePlan, Set-AzAppServicePlan, New-AzAppServicePlan, Remove-AzAppServicePlan...}                                                         
Binary     1.0.0.1    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...}                                                                                 
Binary     1.0.0.1    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...}                                                                                 
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module...}                                                                                           
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module...}                                                                                           
Script     21.0.17279 SqlServer                           {Add-RoleMember, Add-SqlAvailabilityDatabase, Add-SqlAvailabilityGroupListenerStaticIp, Add-SqlAzureAuthenticationContext...}                          


    Directory: C:\windows\system32\WindowsPowerShell\v1.0\Modules


ModuleType Version    Name                                ExportedCommands                                                                                                                                       
---------- -------    ----                                ----------------                                                                                                                                       
Manifest   1.0.0.0    AppLocker                           {Set-AppLockerPolicy, Get-AppLockerPolicy, Test-AppLockerPolicy, Get-AppLockerFileInformation...}                                                      
Manifest   1.0.0.0    BitsTransfer                        {Add-BitsFile, Remove-BitsTransfer, Complete-BitsTransfer, Get-BitsTransfer...}                                                                        
Manifest   1.0.0.0    CimCmdlets                          {Get-CimAssociatedInstance, Get-CimClass, Get-CimInstance, Get-CimSession...}                                                                          
Script     1.0.0.0    ISE                                 {New-IseSnippet, Import-IseSnippet, Get-IseSnippet}                                                                                                    
Manifest   1.0.1.0    Microsoft.PowerShell.Archive        {Compress-Archive, Expand-Archive}                                                                                                                     
Manifest   3.0.0.0    Microsoft.PowerShell.Diagnostics    {Get-WinEvent, Get-Counter, Import-Counter, Export-Counter...}                                                                                         
Manifest   3.0.0.0    Microsoft.PowerShell.Host           {Start-Transcript, Stop-Transcript}                                                                                                                    
Manifest   1.0.0.0    Microsoft.PowerShell.LocalAccounts  {Add-LocalGroupMember, Disable-LocalUser, Enable-LocalUser, Get-LocalGroup...}                                                                         
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-ItemProperty, Join-Path...}                                                                                         
Script     1.0        Microsoft.PowerShell.ODataUtils     Export-ODataEndpointProxy                                                                                                                              
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {Get-Acl, Set-Acl, Get-PfxCertificate, Get-Credential...}                                                                                              
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Format-List, Format-Custom, Format-Table, Format-Wide...}                                                                                             
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Disable-WSManCredSSP, Enable-WSManCredSSP, Get-WSManCredSSP, Set-WSManQuickConfig...}                                                                 
Manifest   1.0.0.0    NetworkSwitchManager                {Disable-NetworkSwitchEthernetPort, Enable-NetworkSwitchEthernetPort, Get-NetworkSwitchEthernetPort, Remove-NetworkSwitchEthernetPortIPAddress...}     
Manifest   1.1        PSDesiredStateConfiguration         {Set-DscLocalConfigurationManager, Start-DscConfiguration, Test-DscConfiguration, Publish-DscConfiguration...}                                         
Script     1.0.0.0    PSDiagnostics                       {Disable-PSTrace, Disable-PSWSManCombinedTrace, Disable-WSManTrace, Enable-PSTrace...}                                                                 
Binary     1.1.0.0    PSScheduledJob                      {New-JobTrigger, Add-JobTrigger, Remove-JobTrigger, Get-JobTrigger...}                                                                                 
Manifest   2.0.0.0    PSWorkflow                          {New-PSWorkflowExecutionOption, New-PSWorkflowSession, nwsn}                                                                                           
Manifest   1.0.0.0    PSWorkflowUtility                   Invoke-AsWorkflow                                                                                                                                      
Manifest   1.0.0.0    TroubleshootingPack                 {Get-TroubleshootingPack, Invoke-TroubleshootingPack}                                                                                                  
Manifest   1.0.0.0    WebAdministration                   {Start-WebCommitDelay, Stop-WebCommitDelay, Get-WebConfigurationLock, Remove-WebConfigurationLock...}                                                  


    Directory: C:\Program Files (x86)\Red Gate\SQL Change Automation PowerShell\Modules


ModuleType Version    Name                                ExportedCommands                                                                                                                                       
---------- -------    ----                                ----------------                                                                                                                                       
Script     3.0.7.2861 SqlChangeAutomation                 {Export-DatabaseBuildArtifact, Export-DatabaseReleaseArtifact, Export-DatabaseTestResults, Import-DatabaseBuildArtifact...}                            


    Directory: C:\Program Files\Microsoft\HybridConnectionManager 0.7


ModuleType Version    Name                                ExportedCommands                                                                                                                                       
---------- -------    ----                                ----------------                                                                                                                                       
Binary     1.0        HybridConnectionManager             {Add-HybridConnection, Get-HybridConnection, Remove-HybridConnection, Set-HybridConnectionManagerConfiguration...}                                     

Debug output

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Pragma                        : no-cache
Strict-Transport-Security     : max-age=31536000; includeSubDomains
x-ms-request-id               : 4092c153-21e9-4b5a-8557-17635086478b
x-ms-ratelimit-remaining-subscription-reads: 11981
x-ms-correlation-request-id   : d384c6a9-e60f-43da-90a8-3ade9a250666
x-ms-routing-request-id       : UKSOUTH2:20190531T123516Z:d384c6a9-e60f-43da-90a8-3ade9a250666
X-Content-Type-Options        : nosniff
Connection                    : keep-alive
X-WebMarshal-RequestID        : BCFBCE9B-05C3-4ADA-B17A-C6C5B77A1DAA
Cache-Control                 : no-cache
Date                          : Fri, 31 May 2019 12:35:16 GMT
ETag                          : "AAAAAAAAC0g="
Server                        : Microsoft-HTTPAPI/2.0
Via                           : 1.1 UKWMG1

Body:
{
  "id": "HIDDEN",
  "type": "Microsoft.ApiManagement/service/apis",
  "name": "89534943f6a946e289cd5be21dfc1f1e",
  "properties": {
    "displayName": "HIDDEN",
    "apiRevision": "1",
    "description": null,
    "serviceUrl": null,
    "path": "testapi112111",
    "protocols": [
      "https"
    ],
    "authenticationSettings": {
      "oAuth2": null,
      "openid": null
    },
    "subscriptionKeyParameterNames": {
      "header": "Ocp-Apim-Subscription-Key",
      "query": "subscription-key"
    },
    "isCurrent": true
  }
}

Error output


@markcowl

This comment has been minimized.

Copy link
Member

@markcowl markcowl commented May 31, 2019

@solankisamir Can you take a look?

@Danlewis3

This comment has been minimized.

Copy link
Author

@Danlewis3 Danlewis3 commented Jun 5, 2019

@solankisamir have you managed to take a look as this effects my CI/CD pipeline i am building

@PinakiIT

This comment has been minimized.

Copy link

@PinakiIT PinakiIT commented Jun 10, 2019

Similar issue. Works locally, but OpenAPI specification format is not recognized on Azure DevOps pipeline:
image

@solankisamir

This comment has been minimized.

Copy link
Member

@solankisamir solankisamir commented Jun 17, 2019

@Danlewis3 acknowledge this as a bug in the Backend. The Url can currently be overridden by a property BackendUrl in the Contract, which we have not exposed.

We should have re-used an existing property ServiceUrl. We are working on a fix in the Backend.

PUT https://management.azure.com/subscriptions/subid/resourceGroups/rgName/providers/Microsoft.ApiManagement/service/testapiservice5/apis/b21793f6af4149ceb0c28fc20164eec8?api-version=2019-01-01

{
'format': 'openapi+json',
'value': open api doc inline,
'path': 'testapi112111',
'backendUrl' : 'ServiceUrl should come here'
}

@solankisamir

This comment has been minimized.

Copy link
Member

@solankisamir solankisamir commented Jun 18, 2019

Similar issue. Works locally, but OpenAPI specification format is not recognized on Azure DevOps pipeline:
image

This is not related to this issue. Please update your Az.ApiManagement module

@PinakiIT

This comment has been minimized.

Copy link

@PinakiIT PinakiIT commented Jun 18, 2019

@solankisamir This is a Azure DevOps release pipeline step screenshot Iv'e sent. How do I update a module here, and even if iti s possible, how do I avoid it to be "updated" every release trigger?. I believe there should be like a new release step agent altogether that does not include the AzureRM module by default, and using the correct Azure AZ modules.

@mjconnection mjconnection added the Bug label Jun 18, 2019
@Danlewis3

This comment has been minimized.

Copy link
Author

@Danlewis3 Danlewis3 commented Jul 5, 2019

So there is a way to get around this issue. If you use set-AzApiManagementApi after the import you can set the URL afterwards.

@krispenner

This comment has been minimized.

Copy link

@krispenner krispenner commented Jul 29, 2019

Ran in to the same issue myself, @Danlewis3's workaround also worked for me, example below for anyone else.

# import the swagger definition
Import-AzApiManagementApi -Context $apiContext -ApiId $ApiId -SpecificationFormat "Swagger" -SpecificationUrl $SwaggerUrl -Path $ApiPath -ServiceUrl $ServiceUrl -ErrorAction Stop

# due to a bug in Import-AzApiManagementApi, which does not honor the -ServiceUrl parameter, we must re-apply the ServiceUrl via Set-AzApiManagementApi
# https://github.com/Azure/azure-powershell/issues/9336
Set-AzApiManagementApi -Context $apiContext -ApiId $ApiId -Name $ApiName -Path $ApiPath -Protocols @("https") -ServiceUrl $ServiceUrl -ErrorAction Stop

Oddly, I also needed to specify the API Name and/or Path and/or Protocols parameters in the Set-AzApiManagementApi call which may be another issue (unrelated) as the documentation suggests that just the Context and ApiId are all that is required. Otherwise I was receiving a "Value cannot be null. Parameter name: source" (probably some underlying LINQ extension method NRE).

For example, I would have expected the below to work, but it does not:

Set-AzApiManagementApi -Context $apiContext -ApiId $ApiId -ServiceUrl $ServiceUrl -ErrorAction Stop
@ToMakeSense

This comment has been minimized.

Copy link

@ToMakeSense ToMakeSense commented Jul 30, 2019

@Danlewis3 @krispenner The work around combining Import-AzApiManagementApi and Set-AzApiManagementApi is also works for setting display name, see: #9428.

As Import-AzApiManagementApi and New-AzApiManagementApi use the same API Apis - Create Or Update to get API created. Not sure if it's better implement that Import-AzApiManagementApi could have all the properties that New-AzApiManagementApi and Set-AzApiManagementApi have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.