It doesn't print the requested query.

Carlos Jahir Carreño Hernandez 125 Reputation points
2023-10-17T19:45:47.28+00:00

Well, I've achieved authentication already. Now, as the next step, I want it to print a simple query. I know it's returning information, but I don't see the query data.

In Microsoft Graph, this is the query and the response.

enter image description here

The following code was created so that when I run it, it provides me with the same information as the device listing.




using System;
using System.Threading.Tasks;
using Azure.Identity;
using Microsoft.Graph;

namespace new_project
{
    class Program
    {
        static async Task Main(string[] args)
        {
            string[] scopes = {"https://graph.microsoft.com/.default"};
           // Values from app registration
           var clientId = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
           var tenantId = "xxxxxxxxxxxxxxxxxxxxxxx";
           var clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
           // using Azure.Identity;
           var options = new ClientSecretCredentialOptions
           {
            AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,
            };
            var clientSecretCredential = new ClientSecretCredential(
                tenantId, clientId, clientSecret, options);
                

    var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
    var result = await graphClient.Devices.GetAsync((requestConfiguration) =>
    {
        requestConfiguration.QueryParameters.Select = new string []{ "deviceId" };
    });
    Console.WriteLine(result);
}

}
}
PS C:\Users\cjch1\OneDrive\new_project> dotnet run
Microsoft.Graph.Models.DeviceCollectionResponse

What's wrong with my code or the query? The Azure application already has all the permissions.

enter image description here

thanks

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,533 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,427 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 74,956 Reputation points
    2023-10-17T19:57:50.37+00:00

    the grapepi uses the rest api and returns json. you are using graph sdk which returns objects not json. when you print an object, which just display the classname. you probably wanted to serialize to json for the print.

    also in graphapi explorer you are using your user token, so its your devices. in the program you are using an azure application service account.


0 additional answers

Sort by: Most helpful

Your answer

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