Search code examples
azureodataazure-api-management

Azure API Management Rest api to get all the subscription key throwing 400 error code


I am trying to get all subscription key names that are associated with any APIM products. Could anyone provide me the correct querystring for the request ?

curl --location 'https://gb-apim-dev.management.azure-api.net/subscriptions/b01ac92a-4fd4-9dc5-2506afa98816/resourceGroups/JLL-GB-RG-APIM-Dev/providers/Microsoft.ApiManagement/service/JLL-GB-APIM-Dev/subscriptions?%24filter=%7C%20name%20%7C%20ThoughtSpot-Trusted-Auth%7C%20eq%20%7C&api-version=2022-08-01' \ --header 'Authorization: SharedAccessSignature uid=integration&ex=2023-09-07T08:23:24.0288132Z&sn=fdfd+ggg=='

Above is the curl, I am using. I am strugle to pass the correct $filter syntax in query string.

$filter : | name | ThoughtSpot-Trusted-Auth| eq | --- is this correct ? $filter : {| name | ThoughtSpot-Trusted-Auth| eq |} --- this one ?

I know the syntax for the filter is wrong but could not get any help from any articles.

Here is the microsoft articles for this. https://learn.microsoft.com/en-us/rest/api/apimanagement/current-ga/subscription/list?tabs=HTTP


Solution

  • Initially you can use GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/subscriptions?api-version=2022-08-01 URL to get all the subscription keys which are there in your APIM instance.

    enter image description here

    You can get the ownerId, scope, displayName, stateComment properties from above response which will be used in the $filter parameter as below-

    $filter=contains(properties/scope,'products/starter') or contains(properties/ownerId,'1') and contains(properties/displayName,'test_name')

    enter image description here