I'm creating a C# .Net Core 2.0 console application to read a specific user's email. I successfully got this sample console application working. So authentication is working. I added permissions to Read all User's email. I looked at the API docs and I can't see examples of reading a user's email. Plenty of send examples. Any help appreciated.
Thanks for posting. I got this to work if I comment out the Filter:
GraphServiceClient client = GetAuthenticatedClient();
string subject = "RE: ACTION NEEDED:";
string dt = "2018-10-5T00:00:00";
IUserMessagesCollectionPage msgs = client.Users["UserName#CompanyName.com"].Messages.Request()
//.Filter($"receivedDateTime ge '{dt}'") // Invalid filter
.Filter($"startswith(subject, '{subject}') and receivedDateTime gt {dt}")
.Select(m => new { m.Subject, m.ReceivedDateTime, m.From, m.Body })
.Top(100)
.GetAsync().Result;
int msgCnt = msgs.Count;
I posted something about getting filter to work. startswith works but the date filter fails.
To get each one's mail.
var users = graphClient.Users.Request().GetAsync().Result;
To get the specific user's mail:
List<QueryOption> options = new List<QueryOption>
{
new QueryOption("$filter", "startswith(displayName,'the specific user's mail')")
};
var users= await graphClient.Users.Request(options).GetAsync();
//Or
var users = await graphClient.Users.Request().Filter("startswith(displayName,'help')").GetAsync();
Get Mail:
foreach (var item in users)
{
string currentMail=item.Mail;
}
Update 2018-10-7
For your updated post:
You can use the following API to filter the mails:
https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$filter=ReceivedDateTime ge 2018-10-04 and startswith(subject,'{subject}')
Related
I am trying to filter out the groups of a user he is a member of based on some words that the group name may contain.
I am using this code -
var groups = _graphServiceClient.Me.MemberOf.Request().Filter($"displayName -eq 'abhi'").GetAsync().Result;
but I am getting the error that filter request is invalid.
Any help with this is always appreciated, thanks.
Based on aad advanced queries here your request is supported when the request headers contains ConsistencyLevel = eventual and count = true
To get it to work here is the sample code:
List<Option> options = new List<Option>();
options.Add(new HeaderOption("ConsistencyLevel", "eventual"));
options.Add(new QueryOption("$filter", $"displayName eq 'abhi'"));
options.Add(new QueryOption("$count", "true"));
var groups = await graphServiceClient.Me
.MemberOf
.Request(options)
.GetAsync();
I am trying to access Teams-Ressourcec via the Microsoft graph-API. I seem to hit a wall with that. The app has the required permissions (as listed in MS documentation)
Queries I've tried:
A simple GET:
string querystring = "api-version=1.6";
var uri = "https://graph.windows.net/contoso.onmicrosoft.com/teams/" + TeamID+ "/channels?" + querystring;
Console.WriteLine(uri);
HTTPClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", result);
var GetResult = await HTTPClient.GetAsync(uri);
This one works with delegated permissions in Graph Explorer (v1.0) however it uses delegate user permissions, and not app permissions.
POST for migration team reation:
string querystring = "api-version=1.6";
var uri = "https://graph.windows.net/contoso.onmicrosoft.com/teams?" + querystring;
HTTPClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
HttpRequestMessage Content = new HttpRequestMessage();
Content.Content = new StringContent("{ \"#microsoft.graph.teamCreationMode\": \"migration\", \"template#odata.bind\": \"https://graph.microsoft.com/v1.0/teamsTemplates('standard')\", \"displayName\": \"My Sample Migration Team\", \"description\": \"\", \"createdDateTime\": \"2020-03-14T11:22:17.043Z\" }", Encoding.UTF8, "application/json");
var GetResult = await HTTPClient.PostAsync(uri, Content.Content);
For both of those, I receive "Resource not found for the segment 'teams'.
Has anybody seen That? How can I acces\work with Teams resources via Graph API?
When you call https://graph.windows.net, this is Azure AD Graph which is deprecated and will be decommissioned from June 30th 2022.
I recommend you switch over to use Microsoft Graph which you call https://graph.microsoft.com/version. See Graph Explorer to get started.
Check List Channels on how to list teams channels using MS Graph.
My goal is simple.
I want to send an automated chat message in to a MS Teams channel using the graph API.
This seems to be beta feature of the graph API and is only avalible in the Microsoft.Graph.Beta.
I have read the docs and have been trying to follow this example:
https://learn.microsoft.com/en-us/graph/api/channel-post-messages, I have all the permissions set correct in my azure portal. I keep getting 'Unknown Error' I have tried:
var graphServiceClient = MicrosoftGraphService.GetGraphServiceClient();
var chatMessage = new ChatMessage
{
Subject = null,
Body = new ItemBody
{
ContentType = BodyType.Text,
Content = messageText
}
};
var response = await graphServiceClient.Teams["77f9c17f-54ca-4275-82d4-fff7esdacda1"].Channels["2007765c-8185-4cc7-8064-fb1b10f27e6b"].Messages.Request()
.AddAsync(chatMessage);
I have also tried to to see if I can get anything from teams:
var teams = await graphServiceClient.Teams["77f9c17f-54ca-4275-2sed4-ffsde59acda1"].Request().GetAsync();
Again all I get is Unknown error, I have used GRAPH API before to do things like get users in an organisation, so I know the genreal set up is correct.
Has anyone on the Internet somewhere in the world got this to work?! becuase its driving me crazy
Same problem here :
Everything is ok with users or groups, but I can't get anything from Teams (unknownError)
All IDs are correct and checked
Here are the authorizations I have set for the app :
Read all users' teamwork activity feed
Read all groups
Send a teamwork activity to any user
Get a list of all teams
Here is my code (based on microsoft daemon app scenario)
The access token is ok
var graphClient = new GraphServiceClient(
"https://graph.microsoft.com/beta",
new DelegateAuthenticationProvider(async (requestMessage) =>
{
requestMessage.Headers.Authorization =
new AuthenticationHeaderValue("Bearer", result.AccessToken);
}));
var chatMessage = new ChatMessage
{
Subject = "Message de test",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Contenu de test"
}
};
await graphClient.Teams["218a4b1d-84d5-48a2-97a0-023e4e4c3e85"].Channels["19:adbf8ddf37a049aa9f63a0f8ee0e8054#thread.tacv2"].Messages
.Request()
.AddAsync(chatMessage);
And the result :
Token acquired
Code: UnknownError
Inner error:
AdditionalData:
request-id: e2e433d8-cedd-4401-b5b2-6f34cf5611cf
date: 2020-03-30T12:14:15
ClientRequestId: e2e433d8-cedd-4401-b5b2-6f34cf5611cf
Edit(2020-04-01) :
No solution at the time being : there are answers to comments at the bottom of the page "Create chatMessage in a channel" in ms doc (feedback section)
It seems that applications cannot be granted the permission to send chatMessages up to now.
RamjotSingh commented on Jun 11, 2019 Contributor
#pythonpsycho1337 - As the permission table above notes, Application
only context is not supported on this API at the moment.
RamjotSingh commented on Dec 16, 2019 Contributor
Supporting application permissions is something we plan to do but we do not have a date yet.
RamjotSingh commented a day ago Contributor
We will share on Microsoft Graph Blog once we have application
permissions for this API. Since the original question for this issue
was answered. Closing it.
I'm currently trying to develop an application that creates Skype meetings.
I'm leveraging the C# UCWA SDK and developing against Skype for Business online.
Meeting creation works fine if I only include people from the tenant in attendees, as soon as I include people not from the tenant in the meeting I get this error message:
{"code":"BadRequest","subcode":"ParameterValidationFailure","message":"Please check what you entered and try again.","debugInfo":{"diagnosticsCode":"2"}}
Here is my code sample
var meeting = new MyOnlineMeeting()
{
AccessLevel = AccessLevel.Everyone,
Attendees = new string[] { $"sip:{Settings.SkypeUserEmail}" }, //Adding anybody else than the service account makes it fail for now
Subject = series.Subject,
ExpirationTime = DateTime.Now.AddDays(3),
AutomaticLeaderAssignment = AutomaticLeaderAssignment.SameEnterprise,
Leaders = series.Organizers.Select(x => $"sip:{x.EmailAddress}").ToArray(),
LobbyBypassForPhoneUsers = LobbyBypassForPhoneUsers.Enabled,
PhoneUserAdmission = PhoneUserAdmission.Disabled
};
var dialIn = await client.OnlineMeetings.GetPhoneDialInInformation();
var meetings = await client.OnlineMeetings.GetMyOnlineMeetings();
var result = await meetings.Create(meeting);
Adding external users to the organizers properties works fine though.
My question is: how can I add external attendees to the meeting I'm creating? Is there anything specific around attendees?
After a few exchanges on the Microsoft Skype for Business MVP's private distribution list, it appears that attendees have to be part of the organization or otherwise the call will fail.
Submitted a Pull Request to update the latest version of the documentation
I have one Odata service , which is providing me the data and I am able to display this data on table. We are going to deploy this application to Launchpad. Now we have this requirement in which logged in user must get the data according to his/her login ID. So If my user ID is XXXXX , I should get the records only for XXXXX. I am unable to understand the process flow. Shall we implement the logic in Odata itself or should I get all the data and filter the model on UI, before displaying it.
Regards,
MS
In oData itself you can access login user by sy-uname. using that user you can filter your data.
OR
In front end you can access login user by below code
var vUrl = "proxy/sap/bc/ui2/start_up";
var oxmlHttp = null;
oxmlHttp = new XMLHttpRequest();
oxmlHttp.onreadystatechange = function() {
if (oxmlHttp.readyState == 4 && oxmlHttp.status == 200) {
var oUserData = JSON.parse(oxmlHttp.responseText);
vUser = oUserData.id;
}
};
oxmlHttp.open( "GET", vUrl, false );
oxmlHttp.send(null);
You have to handle this in Odata only. Get User id from UI using
var storename = sap.ushell.Container.getService("UserInfo").getId();
and set it to Odata to filter and send back the results.
You should handle such requirements in the Service level (OData level), not in the UI.
In DPC_EXT class variable SY-UNAME gives you the logged in user. So you should filter your records by deriving more information from that.