C
C#16mo ago
mitchelldirt

✅ C# Graph API Client

I'm trying to access all of the items in a sharepoint list. I'm just getting an access denied error right now. Using the same site id and list id I can use my account to grab the items, but using the app I can't I think I might need to use the AllowAppOnly flag, but I have no clue how to do that. Anyone go any ideas?
// The request
var result = await client.Sites["siteid"].Lists["listid"].Items.GetAsync();

// How I'm building the graph client
var clientSecretCredential = new ClientSecretCredential(tenantId,clientId,clientSecret);

var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
// The request
var result = await client.Sites["siteid"].Lists["listid"].Items.GetAsync();

// How I'm building the graph client
var clientSecretCredential = new ClientSecretCredential(tenantId,clientId,clientSecret);

var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
16 Replies
HtmlCompiler
HtmlCompiler16mo ago
have you tried with graph explorer
mitchelldirt
mitchelldirtOP16mo ago
Yes, but I could only do it with my account permissions (which worked). The problem is that the application permission isn't working 😦
HtmlCompiler
HtmlCompiler16mo ago
how are the app permissions configured
mitchelldirt
mitchelldirtOP16mo ago
Azure App with Sites.FullControl.All permission enabled Then in the code above I show how I implement the client I am able to query for all users, but not for the items in a list
HtmlCompiler
HtmlCompiler16mo ago
yeah but for example does it require admin consent? i believe it doesn't so it should be ok from that point of view was it created as delegate or app?
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
mitchelldirt
mitchelldirtOP16mo ago
I added the permissions as an application permission and got it approved by an admin. When you say "was it created as delegate or app", does that mean that when creating the app you select what kind of app it will be between those two?
HtmlCompiler
HtmlCompiler16mo ago
no i mean delegate permission or app permission because even if you create an app registration the api permissions needed to do stuff could be those in add permission -> microsoft graph -> delegate permission just be sure to be using the correct ones
mitchelldirt
mitchelldirtOP16mo ago
,Ahhhh yes I'm definitely using app permissions right now. The reason being is that this is supposed to be an automated process and shouldn't require a user to sign in
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
HtmlCompiler
HtmlCompiler16mo ago
do you have your access token?
mitchelldirt
mitchelldirtOP16mo ago
Since I’m using the client secret credential I didn’t find a property on there for access token. I’ll look into it in a bit, but I’m pretty sure it doesn’t provide me with one
HtmlCompiler
HtmlCompiler16mo ago
Choose a Microsoft Graph authentication provider - Microsoft Graph
Learn how to choose scenario-specific authentication providers for your application.
HtmlCompiler
HtmlCompiler16mo ago
Build .NET apps with Microsoft Graph and app-only authentication - ...
In this tutorial, you'll build a .NET app that uses the Microsoft Graph API to access data using app-only authentication.
HtmlCompiler
HtmlCompiler16mo ago
Get access without a user - Microsoft Graph
Learn how an app obtains an access token from the Microsoft identity platform and calls Microsoft Graph with its own identity.
mitchelldirt
mitchelldirtOP16mo ago
Ooooo thanks for all these resources - you were right about the permissions. After another closer look I had the right name for the permission, but I had the SharePoint API Sites.ReadWrite.All NOT the Graph API one As soon as I added in the Graph API Sites.ReadWrite.All permission it started working Thanks for time and help on this 🙂

Did you find this page helpful?