Graph API - filter and select together - 404 error

John Joseph Mathichiparambil - EW 0 Reputation points
2024-05-07T12:55:12.9133333+00:00

When i use 'filter' and 'select' together in a GRAPH API url, it gives a 404 error

This is my URL in web.config - https://graph.microsoft.com/v1.0/users?$select=givenName&$filter=startswith(displayName,'searchName')

Following is the code i use to retrieve data

           string Url = ConfigurationManager.AppSettings["SearchUsingGraphURL"].ToString();

 Url = Url.Replace("searchName", searchkeyword);

            HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(Url);

            webRequest.Method = "GET";

            webRequest.Headers["Authorization"] = "Bearer "+ access_token;

            try

            {

                HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

at this line i get the 404 error.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,781 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 37,551 Reputation points
    2024-05-08T09:34:27.0433333+00:00

    Hi @John Joseph Mathichiparambil - EW

    I recommend that you use the graph SDK to create a graphClient object to call this endpoint. I just tested it locally and it works fine for me.

    var users = await graphClient.Users.GetAsync((requestConfiguration) =>
    {
    	requestConfiguration.QueryParameters.Filter = "startswith(displayName,'xxxxx')";
    	requestConfiguration.QueryParameters.Select = new string []{ "id","givenName" };
    });
    
    

    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.