0

I was trying to import swagger json to APIM through the powershell command. its working for API which is hosted publicly with out any authentication ( ex : https://petstore3.swagger.io/api/v3/openapi.json ) , but when tried to access the swagger which behind AAD it always showing error. like below

Command executed :

$context = New-AzApiManagementContext -ResourceGroupName $resourceGroupName -ServiceName $apimServiceName
$Commonapi = Import-AzApiManagementApi -Context $context -SpecificationUrl $globalCatalog -SpecificationFormat OpenApi -Path $apiPath

Error getting :

Error Code: ValidationError Error Message: One or more fields contain incorrect values: Request Id: 78ee1174-074c-4b84-87ba-95f93313b055 Error Details:  [Code= ValidationError, Message= Parsing     
     | error(s): Failed to import from specified resource https:fqdn/apipath/Swagger/v1/swagger.json: The remote name could not be resolved:
     | 'aud-globalcatalog-kcwg11.dev.kpmg.com'., Target= representation]

So please help is there any other way to fix this ? or is there any way to update the command New-AzApiManagementContext to read the swager.json file kept in a local folder.

Aji
  • 423
  • 8
  • 23

1 Answers1

-1
$ApiMgmtContext = New-AzApiManagementContext -ResourceGroupName "HariTestRG" -ServiceName "krishApi2"
$Commonapi = Import-AzApiManagementApi -Context $ApiMgmtContext -SpecificationFormat OpenApi -SpecificationUrl https://petstore3.swagger.io/api/v3/openapi.json -Path "apis"

Result:

enter image description here

enter image description here

Failed to import from specified resource https:fqdn/apipath/Swagger/v1/swagger.json

Please check the values passed to the parameters apiPath and globalCatalog is specified correctly for importing the swagger API to the APIM Instance.

Note: The above cmdlets taken from the GitHub Reference of Azure PowerShell APIM.

  • the problem here is the original Swager path behind AAD and when try to open the swager we need to authenticate so while giving the path in Ps command its not getting the file, the above command is working with sample petstore swagger. The question was as alternate appraoch can we read the swagger.json from the folder where we keep the json file localy. – Aji Jan 13 '23 at 19:16
  • Here is the cmdlet [link](https://github.com/Azure/azure-powershell/blob/main/src/ApiManagement/ApiManagement/help/Import-AzApiManagementApi.md#example-3-import-an-api-from-a-swagger-file-and-update-an-existing-api), where we can upload the .swagger file from local to Azure APIM. –  Jan 18 '23 at 01:29
  • Apologies @Aji, as per my research, we do not have .json file upload format cmdlets. I know Swagger file formats can be JSON or YAML. So we have a cmdlet to upload the .swagger file as I have given in above link. Please check once. –  Jan 18 '23 at 01:31