Graph API query params doesn't works, getting default results only

Vik 45 Reputation points
2024-01-23T00:30:42.3666667+00:00

Hi All; I am facing a strange issue with Graph API.

While I have tried many different configurations (including the query params $filter, $top and header config),I keep getting the query's default 100 records.  "[https://graph.microsoft.com/v1.0/applications?$filter=startsWith(displayName](https://graph.microsoft.com/v1.0/applications?$filter=startsWith(displayName"https://graph.microsoft.com/v1.0/applications?$filter=startswith(displayname"), 'SearchText')"

Below are things I have already tried

But all the time, there is no change in the result.

Below is the code I'm using

$context = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile.DefaultContext

            $graphToken = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.AuthenticationFactory.Authenticate($context.Account, $context.Environment, $context.Tenant.Id.ToString(), $null, [Microsoft.Azure.Commands.Common.Authentication.ShowDialog]::Never, $null, "https://graph.microsoft.com").AccessToken

            $pat = "Bearer $graphToken"

            $headers = @{

              "Authorization" = $pat

              "ConsistencyLevel" = "eventual"

              "Content-Type" = "application/json"

            }

            $applicationsURL = "https://graph.microsoft.com/v1.0/applications?$filter=startsWith(displayName, 'Text')&$top=999"

            $applications = Invoke-RestMethod -Method GET -Uri $applicationsURL -Headers $headers


Also, I tried with $applicationsURL = "https://graph.microsoft.com/beta/applications?$incorrectParam=true&$fail=true", which, too, is returning the same result while it should fail.

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Answer accepted by question author
  1. CarlZhao-MSFT 46,406 Reputation points
    2024-01-23T07:54:58.42+00:00

    Hi @Vik

    When I tested locally using your script, I had the same problem as you, it only seemed to return 100 app objects.

    User's image

    Since AAD PowerShell is about to be deprecated, I migrated it to MS graph PowerShell. After that it worked fine and returned all the data.

    Connect-MgGraph -Scopes "Application.ReadWrite.All"
    Import-Module Microsoft.Graph.Applications
    $appLists = Get-MgApplication -Top 999 -CountVariable CountVar  -ConsistencyLevel eventual 
    $appLists.Count
    

    User's image

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    1 person found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Diah.Karim-MSFT 335 Reputation points Microsoft External Staff
    2024-01-23T03:07:26.0966667+00:00

    Hi Vik, Can you try to call the endpoint from Graph Explorer? I have tried it and see the response objects not limited to 100 records (as Max Limit should be 999). This is sample endpoint been called : https://graph.microsoft.com/v1.0/applications?$filter=startswith(DisplayName,'Test')&$top=999&$count=true i have registered 126 apps from App Registration start with Test. Below is the result as you can see the count return is 126 User's image

    Hope this helps. If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

  2. Vik 45 Reputation points
    2024-01-23T03:35:47.3533333+00:00

    Hi Diah.Karim-MSFT, thanks for looking into this. Although I haven't tried with Graph Explorer, even if it did, I won't be able to use that for an automated solution. Did you get a chance to run the code I have provided?

    0 comments No comments

  3. Vik 45 Reputation points
    2024-01-23T04:00:33.37+00:00

    Hi Diah.Karim-MSFT, thanks for looking into this. Although I haven't tried with Graph Explorer, even if it did, I won't be able to use that for an automated solution. Did you get a chance to run the code I have provided?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.