0

We're going to use Azure APIM as a gateway in front of our back end APIs. We plan to correlate Azure-managed subscriptions to our users. So we're forwarding the subscription key from the request to our back end and would like to look up the subscription using that [primary or secondary] key. However, I don't think i see a way using the Azure REST API. Is there such an operation exposed anywhere?

I've looked through the Azure APIM REST docs to no avail.

  • You can make use of Get Subscription API here - https://learn.microsoft.com/en-us/rest/api/apimanagement/current-ga/subscription/get?tabs=HTTP and filter the properties by properties.primaryKey and properties.secondaryKey – SiddheshDesai Apr 27 '23 at 13:45
  • @SiddheshDesai Which specific endpoint are you referring to? The only one I would think could _possibly_ be used is "List" but that one doesn't include the primary or secondary keys. – Jason Harper Apr 28 '23 at 17:07

2 Answers2

0

In order to retrieve both the Primary and Secondary Subscription keys for APIM Service you can call the API like below:-

I have referred this MS Document's Rest API

Make sure you append the above document's Rest API with /listSecrets and call it as a POST request to get the Primary and Secondary Keys like below:-

Request:-

POST 
https://management.azure.com/subscriptions/xxxx-xxx-44d6-b4fd-xxxxxx/resourceGroups/siliconrg/providers/Microsoft.ApiManagement/service/siliconapim123/subscriptions/xxxxxx8dba6b004f0xxx/listSecrets?api-version=2022-08-01

Output:-

enter image description here

SiddheshDesai
  • 3,668
  • 1
  • 2
  • 11
  • This is useful if you know the subscription id, but what if all you have is the key (primary or secondary) - how can you look up a subscription with only a key (which presumably APIM does)? – Jason Harper May 08 '23 at 19:47
0

You probably want to cache the result of all "key to subscription" options anyways. So a possible solution would be to first iterate though all APIM subscriptions, then retrieve their primary+secondary keys. Store the results in a way that fits your needs.

Get all APIM subscriptions:

GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/subscriptions?api-version=2022-08-01

Get all subscription secrets:

POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/subscriptions/{sid}/listSecrets?api-version=2022-08-01

Alex AIT
  • 17,361
  • 3
  • 36
  • 73