$count=true support in OneDrive API? - microsoft-graph-api

It looks like the OData $count parameter is not (yet?) supported in the Microsoft Graph API v1.0 for OneDrive.
Request URL: https://graph.microsoft.com/v1.0/me/drive/root/children?$count=true
Response:
{
"error": {
"code": "",
"message": "The query specified in the URI is not valid. Query option 'Count' is not allowed. To allow it, set the 'AllowedQueryOptions' property on EnableQueryAttribute or QueryValidationSettings.",
"innerError": {
"request-id": "e65aff74-1c6f-434b-8cd3-04e0c247fb71",
"date": "2016-10-19T09:48:39"
}
}
}
Is this understanding correct?

The $count parameter isn't supported with OneDrive. You can get a count of the children however by moving one level up:
/v1.0/me/drive/root/
This includes a folder property that contains the number of child items:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('id')/drive/root/$entity",
"createdDateTime": "2012-08-03T08:12:58Z",
"id": "{id}",
"lastModifiedDateTime": "2016-10-18T14:19:21Z",
"name": "root",
"webUrl": "{webUrl}",
"folder": {
"childCount": 28
},
"root": {},
"size": 0,
"specialFolder": {
"name": "documents"
}
}

Related

Graph API search query error - Unexpected segment DynamicPathSegment. Expected property/$value

I am unable to search using microsoft graph api. The documentation is here.
Below is the sample provided in documentation, which itself is not working. Can someone suggest please. I actually want to search for people (and as per documentation /search is recommended way over /people. with /people query I am getting issue as faced in another thread)
URL : https://graph.microsoft.com/v1.0/users/<my mailbox name>/search/query
Request data:
{
"requests": [
{
"entityTypes": [
"message"
],
"query": {
"queryString": "contoso"
},
"from": 0,
"size": 25
}
]
}
Response:
{
"error": {
"code": "Request_BadRequest",
"message": "Unexpected segment DynamicPathSegment. Expected property/$value.",
"innerError": {
"date": "2023-01-18T16:19:05",
"request-id": "29a310fe-b5cf-4ea1-a995-3a09941d6d13",
"client-request-id": "29a310fe-b5cf-4ea1-a995-3a09941d6d13"
}
}
}
Send the POST request to https://graph.microsoft.com/beta/search/query endpoint.
POST https://graph.microsoft.com/beta/search/query
Request body
{
"requests": [
{
"entityTypes": [
"person"
],
"query": {
"queryString": "Sandeep"
},
"from": 0,
"size": 25
}
]
}
Searching for people requires delegated permissions.
Searching only works for searching the signed-in user's relevant people, not for searching people relevant to other users.

Enumerate DriveItem resources of a specific Drive given SharePoint URL and using Graph API

I have a SharePoint URL of the form https://organizationname.sharepoint.com/sites/....
I want to use the Graph API to get a list of all resources in this drive. Reading the API documentation it appears that I require the drive-id of this drive in order to perform this request.
/drives/{drive-id}/root/children
Also, according to the answer to a similar stackoverflow question it appears there are no APIs to convert SharePoint URL to OneDrive driveId. Is there a possible workaround? Is there any way to programmatically get a list of resources from a SharePoint URL?
If your SharePoint URL is https://organizationname.sharepoint.com/sites/yourSiteName, then you can issue a request like this via the Graph API (scope Sites.Read.All might be required):
client.api("/sites/organizationname.sharepoint.com:/sites/yourSiteName:/drives").get();
That request will return something like this:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives",
"value": [
{
"createdDateTime": "2021-07-24T23:35:00Z",
"description": "",
"id": "b!A1234567-ZYXWVUTSRQPONMLKJIHGFEDCBA9876543210",
"lastModifiedDateTime": "2021-08-12T16:39:23Z",
"name": "Dokumente",
"webUrl": "https://organizationname.sharepoint.com/sites/yourSIteName/folderName",
"driveType": "documentLibrary",
"createdBy": {
"user": {
"displayName": "abc"
}
},
"lastModifiedBy": {
"user": {
"email": "bla#organizationame.onmicrosoft.com",
"id": "12345678-4321-4321-4321-012345678901",
"displayName": "zz"
}
},
"owner": {
"group": {
"email": "x#y.onmicrosoft.com",
"id": "09876543-1234-1234-1234-012345678901",
"displayName": "Owner of something"
}
},
"quota": {
"deleted": 345678,
"remaining": 27487788453406,
"state": "normal",
"total": 27487790694400,
"used": 96120
}
}
]
}
The id under description is the drive-id. With that you can get /root/children like so:
client.api("/sites/yourorganizationname.sharepoint.com/drives/b!A1234567-ZYXWVUTSRQPONMLKJIHGFEDCBA9876543210/root/children").get();
While there is no single API or algorithm that allows you to programmatically get a list of resources from a SharePoint URL, you can achieve the same with two Graph API requests.

Getting 400 bad request from Microsoft Graph Api for SchemaExtensions

Limit of: 5 extension schema definitions can be written. !
Here is the response
{
"error": {
"code": "BadRequest",
"message": "Limit of: 5 extension schema definitions can be written.",
"innerError": {
"date": "2020-10-26T12:29:47",
"request-id": "requestID",
"client-request-id": "client-requestID"
}
}
}
And here is the request body
{
"id": "myMetaData",
"description": "My description",
"targetTypes": [
"Group"
],
"properties": [
{
"name": "shortName",
"type": "String"
},
{
"name": "supervisor",
"type": "String"
}
]
}
I have used delegated permision and used token generated by password since SchemaExtension needs delegated one and doesn't support application perm.
I got the answer , it was due to limit of the schemaExtensions that could be created other developer on the project already created 5 and since this was the limit set it showed this error

How to filter SharePoint list items by ID using Microsoft Graph Api

How to filter SharePoint list-items by Id.
Id is out-of-the-box field in the SharePoint-list.
I am testing using graph-explorer: https://developer.microsoft.com/en-us/graph/graph-explorer
I tried with these filters
Working filter with Title:
https://graph.microsoft.com/v1.0/sites/root/lists/ba0dc64a-263c-44b6-8160-66a3034a1429/items?$expand=fields&$filter=fields/Title eq '1'
Non-working filter with Id:
https://graph.microsoft.com/v1.0/sites/root/lists/ba0dc64a-263c-44b6-8160-66a3034a1429/items?$expand=fields&$filter=fields/id eq '1'
{
"error": {
"code": "invalidRequest",
"message": "A provided field name is not recognized",
"innerError": {
"request-id": "9f0bd335-bf60-42dd-893e-397fe62bc890",
"date": "2019-05-01T00:25:51"
}
}
}
https://graph.microsoft.com/v1.0/sites/root/lists/ba0dc64a-263c-44b6-8160-66a3034a1429/items?$expand=fields&$filter=fields/Id eq 1
{
"error": {
"code": "BadRequest",
"message": "Invalid filter clause",
"innerError": {
"request-id": "730490af-6b08-4ac1-8259-fa9bb9dd9e46",
"date": "2019-05-01T00:26:28"
}
}
}
A single ListItem resource could be addressed by Id like this (refer Get item endpoint for a more details):
GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items/{item-id}?$expand=fields
where
site-id - identifier of Site resource
list-id - identifier of List resource
item-id - identifier of ListItem resource
To retrieve multiple items by ids, JSON batch endpoint could be utilized, for example:
POST https://graph.microsoft.com/v1.0/$batch
Accept: application/json
Content-Type: application/json
Body:
{
"requests": [
{
"id": "1",
"method": "GET",
"url": "/sites/root/lists/{list-id}/items/{item_id-1}/"
},
{
"id": "2",
"method": "GET",
"url": "/sites/root/lists/{list-id}/items/{item_id-2}/"
}
]
}

How to create item with column that has strange SharePoint internal encoding?

I created a column with the name "col1" in the list through the web interface Office 365. When I tried to get whole info about this column using msgraph request to
GET /sites/{site-id}/lists/{list-id}/columns/{column-id}
I got such the response:
{
"#odata.context": ...,
"columnGroup": "Custom Columns",
"description": "",
"displayName": "col1",
"enforceUniqueValues": false,
"hidden": false,
"id": "a9fe9dc8-c5b8-467d-8504-23d95f1cc937",
"indexed": false,
"name": "_x0063_ol1",
"readOnly": false,
"required": false,
"number": {
"decimalPlaces": "automatic",
"displayAs": "number",
"maximum": 1.7976931348623157e+308,
"minimum": -1.7976931348623157e+308
}
}
So the problem is that I cannot create an item with that column (I tried both names "col1" and "_x0063_ol1"). The request was to
POST /sites/{site-id}/lists/{list-id}/items
with the body:
{
"fields": {
"Title": "Test2",
"_x0063_ol1": 42
}
}
I got response:
{
"error": {
"code": "invalidRequest",
"message": "Field '_x0063_ol1' is not recognied",
"innerError": {
"request-id": "dbb98ed3-0c2f-48dc-924e-dd888e70c867",
"date": "2018-05-02T07:41:36"
}
}
}
How can I properly create the item with this column using msgraph API?

Resources