Skip to content

Instantly share code, notes, and snippets.

View maisarissi's full-sized avatar

Maísa Rissi maisarissi

  • São Paulo, Brazil
  • 10:43 (UTC -03:00)
View GitHub Profile
@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();
@maisarissi
maisarissi / ODataCast.cs
Last active February 23, 2023 14:04
msgraph-dotnet-v5-rc-odata-cast
//Fetching the members of a group who are of the type User
var usersInGroup = await graphServiceClient
    .Groups["group-id"]
    .Members
    .MicrosoftGraphUser
    .GetAsync();
List<User> userList = usersInGroup.Value;
//Similarly, members of the group of type ServicePrincipal
@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 / ParameterObject.cs
Last active February 9, 2023 13:58
msgraph-dotnet-v5-rc-parameter-object
//var message = ....
//var saveToSentItems = ...
var body = new SendMailPostRequestBody
{
Message = message,
    SaveToSentItems = saveToSentItems
};
await graphServiceClient.Me
@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 / 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 / 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 / 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 / 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 / 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;
}