Skip to content

Instantly share code, notes, and snippets.

View maisarissi's full-sized avatar

Maísa Rissi maisarissi

  • São Paulo, Brazil
  • 06:02 (UTC -03:00)
View GitHub Profile
@maisarissi
maisarissi / NewRequest.cs
Last active February 8, 2023 20:24
msgraph-dotnet-v5-rc-new-request
//create user using v5
var user = new User()
{
    DisplayName= "Adele V",
};
await graphServiceClient
.Users
.PostAsync(user);
@maisarissi
maisarissi / OldRequest.cs
Last active February 8, 2023 20:25
msgraph-dotnet-v4-create-user
//create user using v4
var user = new User()
{
    DisplayName = "Adele V",
};
await graphServiceClient
.Users
.Request()
.AddAsync(user);
@maisarissi
maisarissi / RequestConfiguration.cs
Last active February 8, 2023 20:26
msgraph-dotnet-v5-rc-request-configuration
var user = await graphServiceClient
.Users["{user-id}"]
.GetAsync(requestConfiguration =>
{
requestConfiguration.Headers.Add("ConsistencyLevel","eventual");
requestConfiguration.QueryParameters.Select = new string[] { "id", "createdDateTime"};
});
@maisarissi
maisarissi / Count.cs
Created February 8, 2023 20:27
msgraph-dotnet-v5-rc-count
var count = await graphServiceClient
    .Users
    .Count //Where applicable to enable the use of $count
    .GetAsync(requestConfiguration =>
        requestConfiguration.Headers.Add("ConsistencyLevel","eventual"));
@maisarissi
maisarissi / CustomAuthFlow.cs
Last active February 8, 2023 20:28
msgraph-dotnet-v5-rc-custom-auth-flow
public class TokenProvider : IAccessTokenProvider
{
public Task<string> GetAuthorizationTokenAsync(Uri uri,
Dictionary<string,
object> additionalAuthenticationContext = default,
CancellationToken cancellationToken = default)
{
var token = "token";
//get the token and return it in your own way
return Task.FromResult(token);
@maisarissi
maisarissi / ErrorHandling.cs
Last active February 8, 2023 20:28
msgraph-dotnet-v5-rc-error-handling
try
{
await graphServiceClient.Me.PatchAsync(user);
}
catch (ODataError odataError)
{
Console.WriteLine(odataError.Error.Code);
Console.WriteLine(odataError.Error.Message);
throw;
}
@maisarissi
maisarissi / Pagination.cs
Last active February 8, 2023 20:28
msgraph-dotnet-v5-rc-pagination
var usersResponse = await graphServiceClient
    .Users
    .GetAsync(requestConfiguration => {
        requestConfiguration.QueryParameters.Select = new string[] {"id", "createdDateTime"};
        requestConfiguration.QueryParameters.Top = 1; });
var userList = new List<User>();
var pageIterator = PageIterator<User,UserCollectionResponse>
    .CreatePageIterator(graphServiceClient,usersResponse, (user) => {
userList.Add(user);
@maisarissi
maisarissi / UserList.cs
Last active February 8, 2023 20:29
msgraph-dotnet-v5-rc-get-user-list
var usersResponse = await graphServiceClient
    .Users
    .GetAsync(requestConfiguration =>
        requestConfiguration.QueryParameters.Select = new string[] {"id", "createdDateTime"});
List<User> userList = usersResponse.Value;
@maisarissi
maisarissi / BackingStore.cs
Last active February 8, 2023 20:29
msgraph-dotnet-v5-rc-backing-store
//get the object
var @event = await graphServiceClient
    .Me.Events["event-id"]
    .GetAsync();
//the backing store will keep track that the property change and send the updated value.
@event.Recurrence = null;// set to null
//update the object
await graphServiceClient.Me.Events["event-id"]
@maisarissi
maisarissi / CreateBothClients.cs
Last active February 9, 2023 13:21
msgraph-dotnet-v5-rc-v1-beta-clients
InteractiveBrowserCredential interactiveBrowserCredential = new ("ClientID");
//create client for calling v1 endpoint and get my info
Microsoft.Graph.GraphServiceClient graphServiceClient = new (tokenCredential, scopes);
var userFromV1 = await graphServiceClient.Me.GetAsync();
//create client for calling beta endpoint and get my info
Microsoft.Graph.Beta.GraphServiceClient betaGraphServiceClient = new(tokenCredential, scopes);
var userFromBeta = await betaGraphServiceClient.Me.GetAsync();