Microsoft Graph SDK get site url after group is created - c#

I try to retrieve the site url when a microsoft-365 group is created in sharepoint using graph sdk. I read from docs that in order to access a group team site I should use GET /groups/{group-id}/sites/root BUT I don't know how to do it.
Also I have tried code below but throws exception that resource was not found.
var site = await graphClient.Sites[$"/groups/{group.Id}/sites/root"]
.Request()
.GetAsync();
I would like to know if I can modify the code above and use the group id to retrieve the active site url.
Thanks in advance.

Try this:
graphClient.Groups["0745be26-2d8a-4f8d-be2d-37356a4794a3"].Sites["root"].Request().GetAsync().Result;
My test result:

Related

Shared Mailbox in Microsoft graph in C#

I'm trying to look for a way to identify shared mailbox and/or convert a regular mailbox to shared in C#.
From what I tried to look for I found nothing using GraphServiceClient.
I'm referring to getting a user with:
var users = await graphServiceClient.Users.Request().GetAsync();
or
var users = await graphServiceClient.Users.Request().Select("MailboxSettings").GetAsync();
and identifying if the user has a regular mailbox or shared.
Note: Not talking about shared folders
is there a way using Microsoft.Graph or any other way to identify and/or convert mailbox in asp?
As this feature is still available only in the Beta endpoint and not in V1.0, You can raise a feature for same and upvote it so that it can be moved to the V1.0 endpoint.
Feature Request:https://techcommunity.microsoft.com/t5/microsoft-365-developer-platform/idb-p/Microsoft365DeveloperPlatform.
Hope this helps.

Read b2c extension attribute using Graph API in C#

We are using the Graph API in C# to read data from AD about users setup in B2C.
We have a number of extension attributes setup in the b2c environment, and we want to be able to read the values of these attributes for users in our C# application.
We can make a successful request to get details on the user using:
graphServiceClient.Users[userId].Request().Select("id,displayName").GetAsync();
Which returns the details on the attributes specified.
However, we can't find an option for getting the extension attribute values back with this request. We have included the name of the attribute using the guid of the application storing the attributes, but the attributes are not returned.
We have also tried the following request, which returns the response of "Extension with given id not found":
var extensionDetails = graphServiceClient.Users[userId].Extensions["extension_{guidWithDashesRemoved}_{attributeName}"].Request().GetAsync();
We are able to do this successfully in Postman with the following get request:
https://graph.microsoft.com/v1.0/users?$select=id,displayName,givenName,postalCode,extension_{guidWithDashesRemoved}_{attributeName}
Has anyone been able to get the extension attribute values back?
The first code is correct. You need to add the extension property into the select query parameter.
var user = await graphServiceClient.Users[userId]
.Request()
.Select("id,extension_{guidWithDashesRemoved}_{attributeName},displayName")
.GetAsync();

MS Graph v1.0 Profile Picture Ressource Not Found

I tried to do the Learning Path on Microsoft. But at Build apps with Microsoft Graph – Associate under Access User Data from Microsoft Graph in Unit 4 of 8 I've get an "Ressource not found" Error. If I try to catch my profile picture in the graph explorer I get an Ressource not found Error too, but under "Beta" it displays my picture. I think this Learn Path is outdated.
My Question is, how can I change the code given in the Learning Path to speaks to the BETA and not v1.0.
var resultsUserPhoto = requestUserPhoto.GetAsync().Result;
This line makes the problem.
Greetings.
I have understood that you are using the Microsoft Graph V1.0 SDK. To hit the beta endpoint for only 1 request you can modify the BaseUrl to graph client and make a beta request.
graphClient.BaseUrl = "https://graph.microsoft.com/beta";
var pictureStream = await graphClient.Me.Photo.Content.Request().GetAsync();
For further referrence see this SO Thread.
This code works for me with both v1.0 and beta but only if I really have profile photo:
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var stream = await graphClient.Me.Photo.Content
.Request()
.GetAsync();
For profile without photo it returns Resource not found.

Get Sharepoint Online Site using C# Graph SDK

I'm trying to use the Graph SDK to get a specific Sharepoint site by URL so I can read and write the list, create document libraries, and add documents to existing libraries.
This works to get the root:
var site = await graphClient.Sites[SPUrl].Request().GetAsync();
This doesn't work to get the site I want:
var site = await graphClient.Sites[SPUrl+"/segment1/segment2/site"].Request().GetAsync();
And this doesn't work to get the site by URL -- it tells me "the provided path does not exist or does not represent a site":
var siteByPath = await graphClient.Sites[SPUrl].SiteWithPath("/segment1/segement2/site").Request().GetAsync();
But using the Graph Explorer, this works:
https://graph.microsoft.com/v1.0/sites/my.site.com:/sites/segment1/segment2/site?$select=id
Using the Graph Explorer I determined that each segment of the URL is considered its own site, but didn't have any luck doing this -- the error is "provided identifier is malformed - id is not valid":
var site = await graphClient.Sites[SPUrl].Sites["segment1"].Request().GetAsync();
What am I missing?
With the Sharepoint CSOM you could just ask for a site by its URL. My application is in Azure now and being authenticated by through OAuth tokens, not by a username and password handled within the application, so I'm not sure I can pass that authentication through CSOM. As far as I can tell I need to use Graph now.
It would appear that the problem was that if you're going to query the sites under a site root, you need to add the ":" to your original root site string. So
"await graphClient.Sites[SPUrl].Sites["/segment1/segment2/site"].Request().GetAsync();" needs to be
"await graphClient.Sites[SPUrl+":"].Sites["/segment1/segment2/site"].Request().GetAsync();" which would make it match the syntax used in the Graph Explorer.
I had assumed that asking for a Site using the SDK would handle that, but I was wrong.

Getting facebook group id from group url

i have tried to get facebook group id (gid) by it's url using C#, with no luck.
I have looked over the facebook graph tables, tried PHP, FQL queries, and even tried P3P to get the feed itself of the group page (To get the 'cid' value) - But again - with no luck, I'm getting a token successfully using facebook SDK but I dont understand how to use it to get the group id or the group source code (which always returns the login page), can you help ?
You can fetch the username from the url- string after last /. You can find how to do that. Then simply use the Search API.
You'll be needing a valid user access token with the API call-
/search?q={group-username}&type=group
Example: https://graph.facebook.com/search?q=progressivenagars&type=group&access_token={access-token}

Categories