How to get Gateways details for each API in the APIM Service?

Rajoli Hari Krishna 336 Reputation points
2024-07-09T04:54:14.2766667+00:00

We are getting the API Id of whole APIM service but not for each API in the APIM with the below script:

$apimContext = New-AzApiManagementContext -ResourceGroupName "XXXX" -ServiceName "XXX" 
Get-AzApiManagementGateway -Context $apimContext

 Result:

GatewayId: XXXXX 
Description: 
LocationData :
Id :

We tried another script also i.e.,

$subscriptionId = "<subs_id>" 
$outputCsv = "APIM_API_Endpoints1.csv"

Connect-AzAccount 
Set-AzContext -SubscriptionId $subscriptionId

$apimServices = Get-AzApiManagement 
$apiDetails = @() 
foreach ($apimService in $apimServices) 
{     
$resourceGroupName = $apimService.ResourceGroupName     
$apimServiceName = $apimService.Name         
$apis = New-AzApiManagementContext -ResourceGroupName $resourceGroupName -ServiceName $apimServiceName 
$ApiMgmtContext = Get-AzApiManagementApi -Context $apis
  
foreach ($api in $ApiMgmtContext) 
{         
$apiInfo = [PSCustomObject]@{             
ApimServiceName = $apimServiceName             
ResourceGroupName = $resourceGroupName             
ApiName    = $api.Name             
ApiPath    = $api.Path             
ServiceUrl = $api.ServiceUrl         }       
$apiDetails += $apiInfo     
} 
} 

$apiDetails | Export-Csv -Path $outputCsv -NoTypeInformation 
Write-Output "API details have been exported to $outputCsv"

For this we are getting the below output:

Id                            :  
ResourceGroupName             :  
ServiceName                   : 
ApiId                         :  
Name                          :  
Description                                                                         
ServiceUrl                    :  
Path                          :  
ApiType                       :  
Protocols                     :  
AuthorizationServerId         : 
AuthorizationScope            : 
OpenidProviderId              : 
BearerTokenSendingMethod      :  
SubscriptionKeyHeaderName     :  
SubscriptionKeyQueryParamName :  
ApiRevision                   :  
ApiVersion                    : 
IsCurrent                     :  
IsOnline                      :  
SubscriptionRequired          :  
ApiRevisionDescription        :  
ApiVersionSetDescription      : 
ApiVersionSetId               : 
ContactEmail                  : 
ContactName                   : 
ContactUrl                    : 
LicenseName                   : 
LicenseUrl                    : 
TermsOfServiceUrl             :

How to get the Gateway details configured for each API in the API Management Service using Azure PowerShell script?

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,927 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,283 questions
0 comments No comments
{count} votes

Accepted answer
  1. JananiRamesh-MSFT 23,411 Reputation points
    2024-07-09T10:02:22.6333333+00:00

    @Rajoli Hari Krishna Thanks for reaching out. From the description i understand that you would need to fetch the gateway details for each api in an APIM service.

    i don't see any option to get the gateway details associated with each api. Apis - List By Service - REST API (Azure API Management) | Microsoft Learn

    this rest api lists all the api details for the particular APIM instance, but for each api below are the only properties returned 

    User's image the only way is to use the gateway id, first you need to fetch the gateway id's for each apim instance and with each gateway id you can see the list of api's associated.

    $apimContext = New-AzApiManagementContext -ResourceGroupName "XXXX" -ServiceName "XXX"

    Get-AzApiManagementGateway -Context $apimContext
    this powershell command will return all the self-hosted gateways available for particular APIM instance.
    with that you can use this rest api https://learn.microsoft.com/en-us/rest/api/apimanagement/gateway-api/list-by-service?view=rest-apimanagement-2022-08-01&tabs=HTTP#code-try-0 to see the list of api's associated to that particular gateway using gateway id.

    do let me know incase of further queries, I would be happy to assist you.

    0 comments No comments

0 additional answers

Sort by: Most helpful