Search code examples
azureazure-api-managementapim

Azure APIM: Identifying the API resource id from the portal


I'm following some Microsoft tutorials on APIM from here: https://learn.microsoft.com/en-us/azure/api-management/import-and-publish

I'm upto the section on tracing (https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-api-inspector) and hit a problem trying to locate an API resource ID.

The API in question is from Microsofts Demo Conference API which has been imported and the APIs I've working correctly. For the purpose of this question, I'll choose the GetSpeakers API as an example.

I've followed the instructions to make a POST call from Postman to the following API:

https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/gateways/managed/listDebugCredentials?api-version=2023-05-01-preview

I've taken the following values to mean:

subscriptionId = id taken from subscriptions section uniquely identifying the subscription.

resourceGroupName = the name in text of the resource group containing APIM e.g. my-rg

serviceName = the name in text of APIM e.g. my-apim-test

I've set the access token in Postman under Authorization tab, auth type = bearer and pasted the access token in the Token field. I've added the subscription key to the header under the name ocp-apim-subscription-key.

I've added the body as detailed on the tutorial:

{ "credentialsExpireAfter": "PT1H", "apiId": "", "purposes": ["tracing"] }

I noticed the typo on the website and added double speech marks around the value PT1H.

My issue is finding the API Resource ID for GetSpeakers (from the Demo Conference API).

The request URL is of the format:

https://my-apim-test.azure-api.net/conference-test/speakers

I've tried entering the following values for API resource ID:

  • "https://my-apim-test.azure-api.net/conference-test/speakers"

  • "my-apim-test.azure-api.net/conference-test/speakers"

  • "/conference-test/speakers"

  • "conference-test/speakers"

  • "speakers" ... would have been shocked if this worked!

For all the above I get the same response:

{
    "error": {
        "code": "ValidationError",
        "message": "One or more fields contain incorrect values:",
        "details": [
            {
                "code": "ValidationError",
                "target": "apiId",
                "message": "Invalid field 'apiId' specified"
            }
        ]
    }
}

Does anyone know what is meant by an API Resource ID and how I can see it on the portal?

Thank you.


Solution

  • You can get the apiId of an API either by using Apis - List By Service Rest API or by enabling the trace in APIM instance.

    Fetch it using Rest API-

    enter image description here

    By Enabling Trace-

    enter image description here

    I have used the same apiId in the Gateway - List Debug Credentials to get the trace token.

    enter image description here