Using the Microsoft Graph Explorer, I can use http PUT to create a OneDrive item.
For example, the uri below creates a testfile.txt at my root:
https://graph.microsoft.com/v1.0/me/drive/root:/testfile.txt:/content
Now, I would like the PUT to fail, if the file already exists, and the general documentation on OneDrive items, https://dev.onedrive.com/items/upload_put.htm#optional-query-string-parameters, states how to specify conflict behavior - if I read it correctly, like:
https://graph.microsoft.com/v1.0/me/drive/root:/testfile.txt:/content?#microsoft.graph.conflictBehavior=fail
However, the PUT still successfully overwrites the existing 'testfile.txt'.
Can anyone help me write a PUT query so that it fails in case the item already exists?
Is that even supported by OneDrive?
Do I need to go to the beta version of Microsoft Graph?
Per the documentation this should be specified within request body, not as a query parameter:
{
"item": {
"#microsoft.graph.conflictBehavior": "fail"
}
}
This is also only supported in the Resumable Upload" scenario as the request body for a direct upload is the file itself. In general, the guidance is to always use resumable uploads where possible. Direct uploads are limited to files less than 4MB which makes it unsuitable for most scenarios.
It is also worth noting that the documentation you referenced is for the standalone OneDrive API. While this is very similar to Graph's implementation, they are not entirely interchangeable. The Microsoft Graph documentation is the only authoritative source for Graph information.
Related
I recently started testing the Microsoft Graph APIs, I've been able to successfully upload and delete documents in SharePoint Online document libraries through it.
I have not seen anything documentation around this and would guess it's not supported but wanted to confirm, in case I missed it - Does the Microsoft Graph API support creating document sets and/or updating managed metadata columns?
Based on my test, the managed metadata should have not been supported. Although no official docs states this.
If you cannot get the information by the expand=fields too, I'd suggest you to submit a feature request first: https://officespdev.uservoice.com/
I'm trying to fetch recent files from SharePoint Online using Microsoft Graph.
The API I'm using is :
https://graph.microsoft.com/v1.0/me/drive/recent
But the results include files from all site collection. I need to restrict the results to only a single site collection.
After some research, I found that there is no direct API to restrict the site collection.
I also tried using adding filter like :
$filter=sharepointIds/siteId eq 'site-id'
but it was also not working. It gave a `501 (Not implemented) error.
Update:
I found another API from Graph which is
https://graph.microsoft.com/beta/me/insights/used
which is inside insights(beta) named "items viewed and modified by me"
But it again returns data across tenant and I need to restrict it to a single site collection. I guess filter conditions are not yet implemented for this API in Graph.
Is there any method to get recent files from a particular site collection? Any help is appreciated.
One correction, /me/drive/recent isn't pulling from all site collections, it's pulling from the current user's OneDrive. This includes recent files held within their drive and any recent changes to files that have been shared with them.
As for finding Recent Files from a SharePoint Document Library, you need to make this request within the context of the drive you want to pull from. For example:
https://graph.microsoft.com/v1.0/sites/root/drives/{documentLibraryId}/recent
I'm having some issues using a custom connector to get what I want out of the Microsoft Graph. Essentially, what I am looking to do is take the Email Activity User Detail report and turn it into a Power BI report.
The URL for that report is as follows:
/v1.0/reports/getEmailActivityUserDetail(period='D7')
In order to create this custom connector, I have been using the MyGraph Connector Sample as I'm not very familiar with the use of Power Query, nor the Graph API.
I have created the connector and can connect to the API and everything, but rather than return me the data, all the query does it return me a byte array I can't seem to do anything with.
From looking at Fiddler traces, the actual data I want is being picked up along the way, but it looks like the Graph API uses a redirect URL to the download, which I'm not sure my Power Query code is handling. I think it may just be returning the redirect URL as a string rather than the actual data.
Further to this, my query has no code to handle the NextLink if it goes over the number of returned rows (I think 200?), so I imagine it will not return the full dataset once I do get it working. How is this best handled?
Unfortunately, I am very new to Power Query (this is my first encounter with it, in fact), so I'm not sure where to begin to make the necessary changes to get what I need.
Any assistance would be greatly appreciated.
The Microsoft Graph API - GET Reports in Graph Explorer and Power BI question touches on a similar issue, though that is through the Application interface itself, which seems to be unable to get the necessary authorization tokens by itself.
EDIT: I have managed to fix the issue thanks to the advice from Marc LaFleur.
The problem was indeed that I was trying to use the Odata.Feed as the source. Changing the line:
source = OData.Feed("https://graph.microsoft.com/v1.0/me/", null, [ ODataVersion = 4, MoreColumns = true ])
To:
source = Csv.Document(Web.Contents("https://graph.microsoft.com/v1.0/reports/getEmailActivityUserDetail(period='D7')"))
Fixed the issue and returned the correct values with no other changes.
Microsoft Graph's Reports are not traditional REST endpoints. Rather than returning OData/JSON, they return a temporary URL to a physical file in CSV format.
From the documentation:
If successful, this method returns a 302 Found response that redirects to a preauthenticated download URL for the report. That URL can be found in the Location header in the response.
From the example you linked too, it looks like it is expecting an OData.Feed source (source = OData.Feed). In this case, you're not getting an OData result but rather a URL to a CSV file. I believe you're looking for Csv.Document instead.
I'd like to know if the following is possible.
Swagger is almost what I need to document a Message based API. For instance for a Command Message I'd like to say "Command" instead of "Post", and instead of "path" I'd like to have the name of the Command.
The spec mentions that Vendor Extensions are possible using "x-" properties but I am 1) not finding any examples of how to do this and 2) not sure if the use of these properties would help me meet my goals.
Might anyone be able to point me to some resources that can help me move along?
Swagger is designed to document REST APIs which are based on HTTP verbs. You can't replace verbs or invent new ones.
Vendor extensions are there to allow adding additional information that the specification does not allow, but ultimately, it is still intended for REST APIs.
From what I gather, you're trying to describe something different.
We do welcome suggestions for additional roads for Swagger (that is, cover non-REST APIs), and in order to do that, I'd suggest opening an issue on the swagger-spec repository.
when I look at Gdrive, there is also a fuse client to mount Gdrive. I wonder, when modifying a file on Gdrive through this client, is the file "locked" or in any other way set to "in use" to prevent others to modify the "original" on the internet? I haven't found anything about this. Isn't there a locking method with Google docs api?
Stef Bon
There is no such feature, but you can use the ETag of the file's entry to ensure that no one else has changed the file since it was fetched. This is not exactly the same thing, but it can achieve the same effect of ensuring that changes from one place are not overwritten by changes from another place.
Pretty sure they don't have that. You should consider suggesting it in the Google Docs feature request forums.