How to get file comments using Sharepoint rest api - sharepoint-online

I'm using the following api to successfully get file data:
https://acme.sharepoint.com/sites/my-site/_api/Web/Lists(guid'xxx')/files('yyy')
This is a docx file on which I've posted comments using the web console.
How can I fetch these comments using the rest api? I tried appending /comments to the url, but I'm getting the following 404 error:
{
"error": {
"code": "-1, Microsoft.SharePoint.Client.ResourceNotFoundException",
"message": {
"lang": "en-US",
"value": "Cannot find resource for the request Comments."
}
}
}

The Comments() endpoint currently exists only under the Items() endpoint and not under the Files() endpoint.
Basically, you can access the Comments() functionality only under the below endpoint:
GET https://{site_url}/_api/web/lists/GetByTitle({list_title})/items({item_id})/Comments
You can easily test the above in a PowerAutomate scenario with a Send Http Request to SharePoint actions.
In the below example I attempt to target the file in the document library:
On the other hand, if I attempt to target the file based on the List Item Id that it got in the document library I will get the below response:
As you can see from the above, I am also able to target a specific comment that I left.
Please take note of the below
The Comments() endpoint is not available for MS resources, meaning docx, excels and such files. It is only available for non-MS resource files like pdfs, txts and so on. I am not sure why this rule is in effect but, my best guess would be because there is a "commenting" functionality provided within a Word Document, for example.
You could find a bit more info about the above here.

Related

Microsoft Graph API - How to Delete a Folder with Children

I could use some help deleting a folder using the Microsoft Graph API. The api call below works, but only when the folder is empty and has no children.
DELETE https://graph.microsoft.com/v1.0/drives/{{driveId}}/items/{{driveItemId}}
The folders are created and deleted using the same client application and permissions
It's a folder in a Sharepoint document library if that matters at all
I tried adding an If-Match header with the current eTag of the folder, but that didn't make any difference.
Here's the response I'm getting:
409 Conflict
{
"error": {
"code": "resourceModified",
"message": "The resource has changed since the caller last read it; usually an eTag mismatch",
"innerError": {
"date": "2022-10-17T21:40:30",
"request-id": "b3d35695-...",
"client-request-id": "b3d35695-..."
}
}
}
Is there a way to force the delete, or do I have to clear it out before I can delete it? If I have to clear it out, what's the easiest way to do that?
I tried to reproduce the same in my environment and got below results:
I have one Azure AD application and granted API permissions like below:
To call Microsoft Graph, I acquired access token using client credentials flow via Postman as below:
I created folder in my SharePoint document library using above token with below query:
POST https://graph.microsoft.com/v1.0/drives/<driveID>/items/
{
"name": "Sri Folder",
"folder": { },
}
Response:
When I checked in SharePoint Online, folder created successfully in document library like below:
Now I added children to the created folder by uploading one file to it with below query:
PUT https://graph.microsoft.com/v1.0/drives/<driveID>/items/<driveItemId>:/test.txt:/content
Response:
When I checked the same in SharePoint Online, file is uploaded to the folder successfully like below:
Now, I used the same query as you to delete the folder with children by adding If-match header and got same error like below:
DELETE https://graph.microsoft.com/v1.0/drives/<driveId>/items/<driveItemId>
If-match : etag_value
Response
To resolve the error, you need to replace If-match header with eTag.
I tried the same query by replacing If-match header with eTag, it returned Status: 204 No Content like below:
Response:
When I refreshed the page in SharePoint Online, got this error as folder got deleted along with its children:
I checked opening document library and cannot find the folder as it got deleted successfully:

Accessing Files in a SharePoint Site via Graph: Bad Request

The documentation for using the MS Graph 1.0 API for accessing SharePoint files from libraries seems clear enough, if a bit indirect. My understanding is that I should be able to access the top level item of a library (and then its children via /children) by the following url scheme:
https://graph.microsoft.com/v1.0/sites/<my-tenant>.sharepoint.com:/sites/my-test-site:/drive/root
But I am only getting back an error telling me the Url is invalid:
{
"error": {
"code": "BadRequest",
"message": "Url specified is invalid.",
"innerError": {
"request-id": "08bb72aa-f3be-4df0-b253-dacc4a8fe390",
"date": "2019-07-08T16:38:07"
}
}
}
I've tried a few other url formats as well, such as specifying the drive specifically by Id /drives/<driveId>/root but had the same luck. I'm sure I am misunderstanding something. I'm using the "Path" format (:/sites/path-to-site:/ in the API because it is more natural than going and fetching an Id for everything I need to query.
You need provide global Id of the site you want to access (global Id is <hostName>,<siteCollectionId>,<siteId>).To get the global id, in you test, we can use this.
https://graph.microsoft.com/v1.0/sites/<my-tenant>.sharepoint.com:/sites/my-test-site:/
And below API gives us a list of files on a specified site's default drive:
https://graph.microsoft.com/v1.0/sites/<hostName>,<siteCollectionId>,<siteId>/drive/root/children
If you want to access files on a specific list, all you need is the id of the list:
https://graph.microsoft.com/v1.0/sites/<hostName>,<siteCollectionId>,<siteId>/lists/<listId>/drive/root/children

Deleting a feed using REST API

My requirement is to clear all activities on a notification feed.
Based on this stackoverflow question I understand that there is an undocumented REST API to delete a feed and the dashboard truncate feed functionality uses it.
I tried to replicate the call with the same parameters as dashboard:
DELETE /api/v1.0/feed/notification/f8fa1d12-594a-4b2b-ac58-23c912d1335a/?api_key=...&location=unspecified
Host: api.getstream.io
Authorization: notificationf8fa1d12-xxxx-xxxx-xxxx-23c912d1335a writetoken
stream-auth-type: simple
X-Stream-Client: stream-javascript-client-browser-unknown
Cache-Control: no-cache
Tried to use the same but am getting this error message:
{
"code": null,
"detail": "url signature missing or invalid",
"duration": "6ms",
"exception": "AuthenticationFailed",
"status_code": 403
}
Is this the right way to use this API?
I am using this from Java code and believe that the Java client doesn't have this functionality built in.
There's two ways to do this. You can do it manually from the explorer on the dashboard. Search for the feed, select an activity and press the truncate feed button. This is the easiest way to do this if manually doing this is sufficient.
It's also possible like you found to use the delete API endpoint to do it programmatically. This endpoint is not built in to most clients, including the Java client. The URL and HTTP verb that you used should indeed work.
From what I can tell from your headers and the response it seems like you are having an issue with supplying a correct signature. The easiest way to do this correctly is to use the built in methods in the library you're using to generate them. I'm not an expert in the Java library, but it seems like these methods are inside the StreamRepoUtils class.

OneNote API intermittently returns HTTP 400 when querying O365 SharePoint SiteId

My code calls the OneNote API to resolve a SharePoint Online site URL to a SiteCollectionId and SiteId. We get a bearer token, set the HTTP auth header and issue a GET request to:
https://www.onenote.com/api/v1.0/myorganization/sitecollections/FromUrl(url='https://mytenantxyz.sharepoint.com/sites/copynotesite')
For approx a week, it has been returning the expected response, similar to:
{
"#odata.context": "https://www.onenote.com:576/api/v1.0/$metadata#Microsoft.OneNote.Api.SiteMetadata",
"siteCollectionId": "111e03ac-468c-4a28-9aab-543098ef49bb",
"siteId": "555d72a0-f82f-4e4c-ae8a-17ef0ea04f32"
}
However, today it has decided to return the following in approx 9 out of 10 requests:
{
error": {
"code" : “20158”,
"message": "Unable to get SiteMetadta for the url specified in the request.",
"#api.url": "http://aka.ms/onenote-errors#C20158"
}
}
The Microsoft docs (link) explain error 20158 as:
"Unable to get metadata for the site URL specified in the request. Check the format of the supplied URL. Supported formats include https://domain.sharepoint.com/site-a and https://domain.com/sites/site-a. (SharePoint support is in Preview.)"
I was unaware that this was in preview any more (I thought it was GA), but anyway it doesn't explain why it intermittently works for exactly the same input (same URL and bearer token).
Could it just be a bug in the OneNote API or SharePoint API that it must call under the covers?
Please refer to the blog - http://blogs.msdn.com/b/onenotedev/archive/2015/06/11/and-sharepoint-makes-three.aspx
We added the FromUrl method so you can pass in an absolute site URL and get the site collection and site IDs. You should make this call only when needed, and then store the values (site collection and site IDs) for future use in your requests to the OneNote API.
this however does not answer intermittency. Please share the X-correlationId header with us for a failing request so that we can help further.

Recieve zip file from Box View API

i'm using the Box View API to convert a PDF file to HTML, i'm using the /documents/{id}/content.{extension} section.
The response for this GET call is a .zip file, however i don't know how to retrive it and make downloadable.
Also note that i'm using node.js.
Thanks for your help
You can set your own webhook URL that will be called by Box when your document status changes (one POST on your webhook for "document.viewable", and one for "document.done" plus one "document.error" if an transformation error occured).
Just listen to the "document.done" status and download the assets then. Format that is posted to the webhook you have set looks like :
[{
"type": "document.done",
"data": {
"id": "4cca28f1159c4f368193d5014fabc16e"
},
"triggered_at": "2014-01-30T20:33:04.798Z"
}]
Beware of the docs and check the format programatically. Their API docs are often no quite correct and they post multiple webhooks at the time i'm writing (which is a bug i've reported).
For more info and Box View API docs

Resources