none
Getting issue while Exporting Azure API RRS feed

  • Question

  • Hi,

    I am trying to export Azure API in Swagger format. Below is my script for same. Previously it was working very well. Currently when i run the script again, i am getting the error.

    Script -

    #variables
     
    $path = "W:\Fiverr\API_tool\export-import"
    $subscriptionid = "XXXXXXXXXXXXXXXXXXXXX"
    $resourcegroup = "XXXX"
    $servicename = "XXXXXX"
             
    $APIIDpath = "$path\APIID"
    $apiPATH = "$PATH\api"
    $PRODUCTPATH = "$PATH\PRODUCT"
    $POLICYpath = "$path\policy"
    $namedvalues = "$path\namedvalues"
    $operations = "$path\operations"
    
    #import-module
    get-module -Name azure* -ListAvailable | Import-Module
    
    #Connecting to Azure Subscription
    #Connect-AzureRmAccount  -Subscription $subscriptionid
    $ApiMgmtContext = New-AzureRmApiManagementContext -ResourceGroupName $resourcegroup -ServiceName $servicename
    
    #Export API
    $ApiMgmtContext = New-AzureRmApiManagementContext -ResourceGroupName $resourcegroup -ServiceName $servicename
    $APIS = Get-AzureRmApiManagementApi -Context $apimgmtcontext | Out-GridView -Title " API Selection " -passthru
    $apis | export-csv $APIIDpath\apidetails.csv -NoTypeInformation
    foreach ( $api in $apis ){ $name = $api.name                                               
                               $id = $api.apiid
    						   echo $name-$id
                               try { Export-AzureRmApiManagementApi -Context $ApiMgmtContext -ApiId $id -SpecificationFormat Swagger -SaveAs "$APIpath\API_$id.swagger" -ErrorAction Stop }
                               catch { $a = $_.exception }
                               #exportPolicy
                               #scope= API-scope policy
                               Get-AzureRmApiManagementPolicy -Context $ApiMgmtContext -ApiId $id -SaveAs "$policypath\API_policy_$id.xml" -Force
    						   
    						   $APIoperation = Get-AzureRmApiManagementOperation -Context $ApiMgmtContext -ApiId $id 
    						   
    						   foreach ($oper in $APIoperation) {
    						   echo "OperationID - $($oper.OperationId)"
    						   echo "-----------------------------------"
    								 Get-AzureRmApiManagementPolicy -Context $ApiMgmtContext -ApiId $id -OperationId $($oper.OperationId) -SaveAs "$operations\API_operation_$id-$($oper.OperationId).xml" -Force
    							}
    }

    Error is at line

    try { Export-AzureRmApiManagementApi -Context $ApiMgmtContext -ApiId $id -SpecificationFormat Swagger -SaveAs "$APIpath\API_$id.swagger" -ErrorAction Stop }
                               catch { $a = $_.exception 

    But I am getting exception message

    • Edited by asharma5 Thursday, December 27, 2018 1:16 PM information added
    • Moved by Bill_Stewart Friday, March 15, 2019 4:52 PM This is not "fix/debug/rewrite my script for me" forum
    Thursday, December 27, 2018 1:12 PM

All replies

  • You need to take some time to correctly format you code so that is is readable. You code is very confusing and not properly indented.

    For Azure specific issues you would do better by posting in the Azure forum.  They are the holders of the Azure APis.  This forum is fo general scripting questions.

    https://azure.microsoft.com/en-us/support/community/


    \_(ツ)_/


    • Edited by jrv Thursday, December 27, 2018 6:04 PM
    Thursday, December 27, 2018 6:03 PM