How to get the owner of a SharePoint site? - sharepoint

When querying the Graph for a SharePoint site, the json does not include the owner information.
I found a way workaround to get the owner information, but is it possible to get the owner of the SharePoint site without first querying the default drive?
Workaround:
call /sites/{site-id}/drive
Fetch the drive owner

Site resource does not expose Owner property and indeed it could be retrieved via Site.Drive property. But it is not necessarily to request drive resource separately, the following options are available:
Option 1
Modify your query to request site source along with default drive resource via a single request (using expand parameter)
https://graph.microsoft.com/beta/sites/root?select=*,drive&expand=drive
Option 2
Combine multiple (e.g. get site and get drive) requests using JSON batching:
POST https://graph.microsoft.com/v1.0/$batch
Accept: application/json
Content-Type: application/json
{
"requests": [
{
"id": "1",
"method": "GET",
"url": "/sites/root"
},
{
"id": "2",
"method": "GET",
"url": "/sites/root/drive"
}
]
}

Related

Create Sharepoint Site via REST API with multiple owners

So, I have a Power Automate Flow, which creates a Sharepoint Site using the Sharepoint REST API via "Send HTTP Request to Sharepoint" connector. I`ve following body:
{
"request": {
"Title": "#{variables('strSPName')}",
"Url":"#{variables('strSPAddress')}",
"Lcid": 1031,
"ShareByEmailEnabled":true,
"Description":"-",
"WebTemplate":"SITEPAGEPUBLISHING#0",
"SiteDesignId":"-",
"Owner": "#{outputs('Get_my_profile_(V2)')?['body/mail']}"
}
}
So right now I have only me as owner, but I need an additional owner.
I`ve tried to set two owners in an array like this:
"Owner": ["#{outputs('Get_my_profile_(V2)')?['body/mail']}", "email#test.com"]
Unfortunately, I`m getting the following error:
An unexpected 'StartArray' node was found when reading from the JSON reader. A 'PrimitiveValue' node was expected.
Any suggestions?
Thanks in advance.
As far as I am aware you can only set one owner when creating a site via the SPSiteManager endpoint. However, a workaround could be to add the second user to the Owners group directly after creation with a second POST request.
Below is an example
The principal id of the sitegroup should be 3.
Uri
_api/web/SiteGroups(3)/users
Body
{
"__metadata": { "type": "SP.User" },
"LoginName":"i:0#.f|membership|jane#contoso.onmicrosoft.com"
}

M365 group email change via Graph API

I am trying to change M365 Group email alias [Nickname] with use of Graph API.
Below HTTP call returns 204 [as expected]. Group email stays the same :? I have waited several hours.
I am able to change other group properties [description, display name etc.] with this call
{
"inputs": {
"method": "PATCH",
"uri": "https://graph.microsoft.com/v1.0/groups/GROUPID",
"headers": {
"Content-type": "application/json"
},
"body": {
"mailNickname": "_Display12345"
},
"authentication": {
"audience": "https://graph.microsoft.com",
"clientId": "",
"secret": "",
"tenant": "",
"type": "ActiveDirectoryOAuth"
}
}
}
This might be due to insufficient permissions. Make sure you are allowing the permission according to your account type from Update group - MSFT Docs.
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
Group.ReadWrite.All, Directory.ReadWrite.All
Delegated (personal Microsoft account)
Not supported.
Application
Group.ReadWrite.All, Directory.ReadWrite.All
Now try making the required changes to your attributes (i.e., mailNickname in your case).
To make sure this is working try fetching the details of your group which gives the response with updated attributes.
GET https://graph.microsoft.com/v1.0/groups/<GroupId>
REFERENCES: Get group - MSFT Docs
I have repro the issue the API is working fine and I am able to update the alias [Nickname]
can you please try this in Graph explorer and see if it works.

How to get all events from all rooms (or selected users) in microsoft graph?

I would like to get events from selected rooms in microsoft graph (rooms are users too).
As I understand the API from graph:
I need to call
GET /users/{id | userPrincipalName}/events/
for each user/room to get all events for rooms or I need to create groups and call:
GET /groups/{id}/events/
Is there a possibility to pass more than 1 Id to get different results ?
Or any other way to get events from provided range of users (rooms)?
Cheers
There is no such REST can return the events of multiple users directly. However we can use the batch request to send the multiple request in a single request.
Here is a sample that retrieve events from two users:
POST https://graph.microsoft.com/beta/$batch
Accept: application/json
Content-Type: application/json
authorization: bearer {access_token}
{
"requests": [
{
"id": "1",
"method": "GET",
"url": "/users/user1#{tenantName}.onmicrosoft.com/events"
},
{
"id": "2",
"method": "GET",
"url": "/users/user1#{tenantName}.onmicrosoft.com/events"
}
]
}
To read events from multiple users, Read calendars in all mailboxes is required. You can use the client credential flow to acquire the token for this permission. More detail about batch request please refer link below:
Combine multiple requests in one HTTP call using JSON batching (preview)

Possible to pull Insights data via Instagram API?

Instagram recently allowed accounts to link to a Facebook Business Page. They also added a new 'Insights' section that gives metrics like:
Impressions
Reach
Top Posts
Followers by Age
I can't find a way to pull these new numbers in via the API. Is there a separate Analytics API that I need to apply for?
Quick update for this question: the Instagram Platform API now offers an endpoint for insights.
Endpoint
GET graph.facebook.com
/{media_id}/insights?metric={engagement|impressions|reach|saved|video_views}
Example
GET graph.facebook.com
/17895695668004550/insights?metric=impressions,reach
Example Response
{
"data": [
{
"name": "impressions",
"period": "lifetime",
"values": [
{
"value": 264
}
],
"title": "Impressions",
"description": "Total number of times the media object has been seen",
"id": "17855590849148465/insights/impressions/lifetime"
},
{
"name": "reach",
"period": "lifetime",
"values": [
{
"value": 103
}
],
"title": "Reach",
"description": "Total number of unique accounts that have seen the media object",
"id": "17855590849148465/insights/reach/lifetime"
}
]
}
Having faced this very problem (analytics being confined to the mobile app), I decided to use the Android app SSL Packet Capture (NO root required) to capture the requests (you must manually fetch a post's insights in the app whilst recording). The correct GET request will be listed inside one of the Instagram entries and it's long!
The necessary access token is already embedded in the request and the instagram post id can be substituted to fetch post-level analytics: Reach, Impressions & Engagement. Moreover the GET request must be made over https.
The request (in URL decoded form) will look something like this:
https://graph.facebook.com/graphql?access_token=<ACCESS_TOKEN>&query_id=<QUERY_ID>&locale=en_US&strip_nulls=true&strip_defaults=true&querparams={"0":{"id":"<POST_ID>", "access_token":"<ACCESS_TOKEN_2>:{"_token_ver":2,"_auth_user_id":<USER_ID>,"_token":"<TOKEN>","asns":{"<ASNS>,"time":1476466064},"_auth_user_backend":"accounts.backends.CaseInsensitiveModelBackend","last_refreshed":1476396104.372065,"_platform":1,"_auth_user_hash":""}"}}'

OneDrive for Business Storage/Quota

I'm trying to programatically get OneDrive for Business Storage/Quota for all users within our tenant.
Have tried using the https://mytenant-my.sharepoint.com/_api/site/usage API call, but this doesn't accurately represent the size of our OneDrive usage.
Has anyone had any experience of getting this information and how best to get it?
There is no such endpoint like /sites/usage according to the documentation.
Instead call for GET --> https://{tenant}-my.sharepoint.com/_api/v2.0/drive and get drive information. In the drive response you will be having QUOTA facet.
Sample response response has been truncated for readability.
{
"id": "string",
"driveType": "personal | business",
"owner": { "#odata.type": "oneDrive.identitySet" },
"quota": { "#odata.type": "oneDrive.quota" },
"items": [ { "#odata.type": "oneDrive.item" } ],
"root": { "#odata.type": "oneDrive.item" },
"special": [ { "#odata.type": "oneDrive.item" }]
}
Here you can get the storage/quota information.
You have the right _api format to get the usage statistics but you need to specify the full path to each users' OneDrive for Business site in the URL.
For example:
https://mytenant-my.sharepoint.com/personal/user_mytenant_com/_api/site/usage
For each user in your organisation, call that REST Api URL but replace the user_mytenant_com part with the username of the current user.
By default an Office 365 tenant administrator does not have access to a user's OneDrive for Business site so I don't think you will be able to call the REST Api method without first adding your user as an administrator of their OneDrive for Business site.

Resources