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.
Related
How can I list a SharePoint site's drives using the Graph API for GCC High environments? It works when using the same endpoint in my standard environment. I'm able to list all of the drives. However, in my client's GCC High environment, with the same exact API Permissions on the App Registration in Azure, I can't get it to list anything. It just returns an empty array with a 200 status.
Graph API Endpoint:
https://graph.microsoft.us/v1.0/sites/{{site-id}}/drives
Response:
{
"#odata.context": "https://graph.microsoft.us/v1.0/$metadata#drives",
"value": []
}
API Permissions
This endpoint will return the site's metadata however:
https://graph.microsoft.us/v1.0/sites/{{site-id}}
{
"#odata.context": "https://graph.microsoft.us/v1.0/$metadata#sites/$entity",
"createdDateTime": "2022-10-05T17:42:12.63Z",
"description": "",
"id": "{{site-id}}",
"lastModifiedDateTime": "2022-10-06T10:13:56Z",
"name": "DocumentCenter",
"webUrl": "{{site-url}}",
"displayName": "{{site-name}}",
"root": {},
"siteCollection": {
"hostname": "{{host-name}}"
}
}
After speaking with a Microsoft support specialist I found that my "Grant Type" within my Authorization settings in Postman were incorrect. I was using an Authorization Code, and I needed to use Client Credentials. My App Registration had Application permissions, not Delegated for the SharePoint permissions. So the call was not authorized to return SharePoint lists until I switched to the Client Credential Grant Type.
We're using Microsoft Graph API v1.0 to manage user permissions of folders stored on SharePoint. We want to also add/remove permission to/from a site's pre-built group below.
{
"id": "[removed]",
"roles": [
"read"
],
"grantedToV2": {
"siteGroup": {
"displayName": "XYZ Visitors",
"id": "5",
"loginName": "XYZ Visitors"
}
},
"grantedTo": {
"user": {
"displayName": "XYZ Visitors"
}
}
},
For permission removal, `DELETE .../permission/{id}' API sounds sufficient (docs).
However, we're unable to find an appropriate API to add permission to a siteGroup from the listing above. The only API allowing to add permissions sounds to be POST .../invite API (docs). We are not sure whether this API works for siteGroup nor how to pass the group to the API. Neither searching on the web got us to anything useful.
How to add a read permission to the site's pre-built Visitors group on a drive item using Microsoft Graph v1.0 API? If not, is there an alternative?
When doing a Microsoft Graph /search/query POST such as:
{
"requests": [
{
"entityTypes": [
"event"
],
"query": {
"queryString": "MySearchedText"
},
"from": 0,
"size": 2
}
]
}
The result is fine when I use a personal Microsoft 365 account. But when I use another Microsoft 365 account created by specifying a Yahoo address, it fails, even though I have authorized the calendars.readwrite, user.read and mailboxsettings.read permissions (just like I did with the personal MS account):
{
"error": {
"code": "AuthenticationError",
"message": "Error authenticating with resource",
"innerError": {
"date": "2021-02-14T18:01:59",
"request-id": "c064b190-a39a-4e77-bdc2-fa3d25ebdb90",
"client-request-id": "f78443a1-1d27-c865-567b-9af9beb78933"
}
}
}
However a /me/calendarview query works perfectly (GET https://graph.microsoft.com/v1.0/me/calendarview?startdatetime=2020-02-14T16:33:35.452Z&enddatetime=2024-02-21T16:33:35.452Z).
Do you know if the search/query API requires some specific properties for the user account?
Many thanks for your help, I have spent 1.5 days reading docs, other SO posts, trying various approaches, but nothing helps!
Calendarview works for both work account and personal account, please see this document but search query doesn't work with personal accounts. See this document.
The permissions here specify that you need to have atleast the least privileged permission to get the results if you login with the work or school accounts. And the second thing here is there are no permissions that support personal accounts. That means you cannot make this API call when you login with the personal account. Application - Not Supported means that the App context token doesn't support this call.
I have a shared calendar in Office 365 with read and write permissions and I am trying to get it using Get calendar (V2) connector but it is only getting my own calendar. Is there a way to get shared calendars for Office 365 in Azure logic apps?
For this problem I did some test and it seems the "Get calendar (V2)" action in logic app can't get the calendars which others shared to you. But I provide another solution(use graph api) below for your reference:
1. You need to ask others to share a calendar to you on office 365 web page but not in outlook app.
2. Then you need to create an application in your azure AD, please refer to this tutorial.
In the application you created in azure ad above, please do the steps below:
After that, please do not forget click the "Grant admin consent for xxx" button(Maybe you need to wait a few minutes until this button become clickable).
Then click "Certificates & secrets" in your application in azure ad and new a client secret.(copy this client secret to your note book)
3. Then create a "HTTP" action in your logic app and refer to the screenshot below to request for the access token.
The "client_id" is your appliction id in azure ad, "username" and "password" is your azure user name and password, the "client_secret" is what you got above. This "HTTP" action will help us to get the access token. The response should be like below:
Then we need to parse the response data in json type, you can use "Parse JSON" action.
Use the "Body" from the "HTTP" action and fill in the "Schema" box with the code below:
{
"properties": {
"access_token": {
"type": "string"
},
"expires_in": {
"type": "integer"
},
"ext_expires_in": {
"type": "integer"
},
"scope": {
"type": "string"
},
"token_type": {
"type": "string"
}
},
"type": "object"
}
4. After that, we can create another "HTTP" action in logic app and request the graph api for all of the calendars which you can see (please note there is a space between the "Bearer" and the "access_token").
5. At last, we can get all of the calendars in the second "HTTP" action's "OUTPUTS" box.
Hope it helps~
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":""}"}}'