Posts

Showing posts with the label Graph API

How Get, Set, Delete Permission on SharePoint Online Site using Graph API

Image
How to get SharePoint Site ID [GET] https://graph.microsoft.com/v1.0/sites?search=contoso5 How to set SharePoint Site Permission only to selected App (AAD App reg) [POST] https://graph.microsoft.com/v1.0/sites/demotenant.sharepoint.com,4465d2n7-e7c4-40df-abfa-364106bbc502,57836gs4-b14f-4061-ba63-fdb0c2a923b6/permissions Request Body: ============ {     "roles": [         "write"     ],     "grantedToIdentities": [         {             "application": {                 "id": "3795d2n7-fa6d-4203-9076-5c8898799cb8",                 "displayName": "DemoTenantAADApp"             }         }     ] } How to get SharePoint Site Permission [GET] https://graph.microsoft.com/v1.0/sites/demotenant.sharepoint.com,4465d2n7-e7c4-40df-abfa-364106bbc502,57836gs4-b1...

C# How to Get SharePoint Online Documents Analytics Using Graph API

Image
In this article we will see How to get SharePoint Online documents analytics using the Microsoft Graph API. To get, you will need to: Register an app in Azure AD to authenticate and authorize API requests. Grant the app the necessary permissions to read the documents and their analytics data. Use the API to get the analytics data for the documents. Below is the example of how you can do this in C#: using Microsoft.Identity.Client; using Microsoft.Graph; using System.Net.Http.Headers; // Replace these with your own values. const string clientId = "your-client-id"; const string clientSecret = "your-client-secret"; const string tenantId = "your-tenant-id"; const string resourceId = "https://graph.microsoft.com"; const string siteId = "your-site-id"; // Acquire an access token. var authContext = new AuthenticationContext("https://login.microsoftonline.com/" + tenantId); var clientCredential = new ClientCredential(clientId, clientS...

C# How to Access SharePoint Online Lists using Graph API using MSAL

Image
In this article, we will see how to invoke SharePoint Online Lists using Graph API using MSAL authentication in C#. To access a SharePoint Online list using the Microsoft Graph API with MSAL (Microsoft Authentication Library) authentication in C#, you will need to follow these steps: Register your application with Azure Active Directory (AAD) and grant it the necessary permissions to access SharePoint Online. This will enable your application to authenticate with AAD and obtain access tokens. Install the Microsoft.Identity.Client NuGet package in your C# application. This will allow you to authenticate users and obtain access tokens using the MSAL library. Use the MSAL library to authenticate the user and obtain an access token. This token will be used to authorize your application to access SharePoint Online. Use the access token to make a request to the Microsoft Graph API to retrieve the data from the SharePoint Online list. Here is an example of how you can use the MSAL library to ...

SharePoint Online Access List Item by ID using Graph API

Image
In this page, we will see How to access SharePoint Online List Item by ID using Graph API. Below screenshot is from Graph Explorer ( Graph Explorer | Try Microsoft Graph APIs - Microsoft Graph ).  I have formatted the Graph API url and executed from Graph Explorer and below is the output. Graph API url: https://graph.microsoft.com/v1.0/sites/<site-id>/lists/<list-name>/Items?expand=fields(select=Id,Column1,Column2,Column3)&filter=fields/ID eq <item-id> we have to use header key value (highlighted in green arrow on above screenshot) as because filter works only on indexed columns Header: Prefer   Value:  HonorNonIndexedQueriesWarningMayFailRandomly (Replace the site-id, list-name, column name, item-id with your actual values.) On executing above API with actual values, response will be returned with respective list item However, instead of filter by ID, we can directly access the particular list item by passing ID like below And this is the Microsoft ...

C# How to Call Graph API from Web API using MSAL Authentication

Image
In this article you will see, in C# how to call Graph API from Web API using MSAL Auth using .NET Framework. MSAL auth with Graph API works good on Console app, Azure Func App, etc. But not for Web API, need to handle with Azure Identity.  To make it work on Web API, instead of using Microsoft.Client.Identity we will need to Azure.Identity. Internally Azure.Identity uses the MSAL authentication. So you can use like below. var tenantId = "xxxxx-xxxx-4392-xxxx-xxxxxxxxxx"; var clientId = "xxxxx-xxxx-4203-xxxx-xxxxxxxx"; var clientSecret = "xxxxxzzxxzzzxxzzzzzxxxxxxxx"; var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret); GraphServiceClient graphServiceClient = new GraphServiceClient(clientSecretCredential); var users = graphServiceClient.Users.Request()                   .Select(x => x.DisplayName).GetAsync().Result; Output: You will get result like below. Happy PC (Programming / Configuring)