I have to get data from a excel document which is shared with me. I have to get the cell colors of a lot of cells which takes very long with the graph api since you can only get them cell by cell. So i would like to download it and process it offline.
However since the file is not on my drive I'm not getting the #microsoft.graph.downloadUrl field with the file details request, and I would need to go with the Download File endpoint, which unfortunately returns 404. Is there any suggestion how can this be done?
According to your questions, you want to download a file which is someone shared with you. If I have misunderstand your, please let me know.
I have a preliminary solution like this:
First, we can use the List items shared with the signed-in user API to get the file which is shared with you. The part of the response like this:
{
"id": "1312abc",
"remoteItem": {
"id": "{itemid}",
"name": "March Proposal.docx",
"file": { },
"size": 19121,
"parentReference": {
"driveId": "{driveid}",
"id": "1991210caf!104"
}
}
}
}
From the response, we can get the drive's id and the item's id of the shared file.
Second, we can use the drive's id and the item's id to download the file. The API like this:
GET /drives/{drive-id}/items/{item-id}/content
For more detail, we can refer to the content of Download the contents of a DriveItem
Related
We are integrating our product with MS OneDrive. Our users will connect their MS accounts and choose a folder that they want us to pull files from. Our system only supports certain file types so we have to get the mimetype information AND the file ID after making a request. But we can't find a request that brings back both pieces of information so we can determine if we should pull a file or not.
This is close, but it doesn't give us the mimetype information.
https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/drive_recent?view=odsp-graph-online
Anyone have any ideas?
The get method lets you retrieve all kinds of information about a file: https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_get?view=odsp-graph-online
It returns a driveItem object, that has a file property. And that file property has a mimeType property. See here https://learn.microsoft.com/en-us/onedrive/developer/rest-api/resources/driveitem?view=odsp-graph-online and here https://learn.microsoft.com/en-us/onedrive/developer/rest-api/resources/file?view=odsp-graph-online.
Unfortunately that means, that you will need more than one request to get the information you want.
If filtering by filename suffix is good enough for you, you can query OneDrive like this:
POST /search/query
Content-Type: application/json
{
"requests": [
{
"entityTypes": [
"driveItem"
],
"query": {
"queryString": "filetype:docx OR filetype:doc"
}
}
]
}
Documentation: https://learn.microsoft.com/en-us/graph/search-concept-files#example-5-use-filters-in-search-queries
I have an excel file named "demo.xlsx" uploaded in the root folder of user A's onedrive. This file contains a table named "EmployeeTable". I want to login to my app as a different user - User 'B' and read data from this table.
I tried to login as user B and access the data using
https://graph.microsoft.com/v1.0/users/8e92a7895e495d6623/drive/root:/demo.xlsx:/workbook/tables('EmployeeTable')/rows
here 8e92a7895e495d6623 is user A's id. But I get the following error:
statusCode: 404,
code: "itemNotFound",
body."message":"Item does not exist"
I have tried to share the file with user B by logging in to onedrive as user A and using the 'share' option, but I still get the above error.
When I login to my app as user A, and use the same URI as mentioned above, I am able to retrieve the data correctly.
Can anyone guide me on how to read an excel file from a different user's onedrive folder? I want to be able to keep this excel file in a common area like a user's onedrive folder and have multiple users read from it.
Note: the app that I have built is based on https://github.com/microsoftgraph/angular-excelstarter-sample
If user A shares a file with user B and user B is currently logged in an app then call the endpoint
https://graph.microsoft.com/v1.0/me/drive/sharedWithMe
The response will contain all files shared with user B. Find a file you need. The response should contain remoteItem node with parentReference child node.
"#odata.type": "#microsoft.graph.driveItem",
"createdDateTime": "2021-01-05T09:51:23Z",
"id": "01BDYTYLL573DF4J3A2JG3WPFKMZLLBPQD",
...
"remoteItem": {
"id": "01BDYTYLL573DF4J3A2JG3WPFKMZLLBPQD",
"parentReference": {
"driveId": "b!RdjejBSERkqd6KyrlECzSlClLPMHvAxIle01z5BIuc0OlAR_j4bQQ5j8LT1dXapM",
"driveType": "business",
"id": "01BDYTYLN6Y2GOVW7725BZO354PWSELRRZ"
},
....
Use the driveId and remote item's id and call this endpoint to access data
https://graph.microsoft.com/v1.0/drives/{driveId}/items/{id}/workbook/tables('EmployeeTable')/rows
I am trying to copy an excel file in the same folder in my sharepoint account using following API - POST /drives/{driveId}/items/{itemId}/copy but it gives message 'Operation not supported'.So how to do this?
As discussed in the comments you can try the below scenario.
I have a folder in my drive and it has an excel file. I am trying to copy that file into same folder by using the below call.
https://graph.microsoft.com/v1.0/sites/{siteid}/drives/{driveid}/Items/{file id which you want to copy}/copy
Request Body:
{
"parentReference": {
"driveId": "{Same driveid of above call}",
"id": "{Folderid}"
},
"name": "contosoplan(copy).xlsx"
}
Give a try with this. And as you said the apiversion=2.1 should not me used in some scenarios according to this Github Thread as it doesn't have feature parity with default version.
What is the REST API call to anonymously upload to a publicly shared folder on OneDrive?
I have tried sharing a folder both thru the OneDrive Web UI creating a link attributed with: "Anyone with this link can edit this item", and using the REST API:
POST https://graph.microsoft.com/v1.0/drives/{driveId}/items/{sharedFolderId}/createLink
Content-type: application/json
{
"type": "edit",
"scope": "anonymous"
}
In both cases, I can read from the shared folder without logging on by
GET https://api.onedrive.com/v1.0/shares/{shareId}/items/{sharedFolderId}
I can also read the permission itself using
GET https://api.onedrive.com/v1.0/shares/{shareId}/items/{sharedFolderId}/permissions
=>
{
"#odata.context":"https://api.onedrive.com/v1.0/$metadata#shares('{shareId}')/items('{sharedFolderId')/permissions",
"value":
[
{
"id":"{permissionId}",
"link":
{
"application":
{
"displayName":"{my own app}",
"id":"{short app id}"
},
"type":"edit",
"webUrl":"https://1drv.ms/u/{shareId}"
},
"roles":["write"],
"shareId":"{shareId}",
"expirationDateTime":"0001-01-01T00:00:00Z",
"hasPassword":false
}
]
}
However trying to upload a file or create a subfolder, i.e.
PUT https://api.onedrive.com/v1.0/shares/{shareId}/driveItem:/{filename}:/content
Content-type: text/plain
some text goes here
or
POST https://api.onedrive.com/v1.0/shares/{shareId}/items/{sharedFolderId}/children
Content-type: application/json
{
"name": "TestFolder",
"folder": { }
}
both fail as unauthorized calls - but isn't the whole point of an "edit" link with "anonymous" scope that "anyone with this link can edit this item"?
I have tried various combinations of https://graph.microsoft.com/v1.0 instead of https://api.onedrive.com/v1.0 and /drives/{driveId} instead of /shares/{shareId} as well as /shares/{shareToken}, where shareToken is the "u!"-encoding of the webUrl from the link in the permission.
So far without being able to figure out the right REST API call. I hope someone is able to help :-)
You can download my TestOneDrive Visual Studio test project to reproduce the issues. It also contains initialization code to create and share the folder.
Due to no guys from Product Group following this and no official docs announced this, so I suggest you to submit an feature request first on UserVocie or vote up an existing one close to your issue.
I am using MusicBrainz to get a track's meta data. I want to get the track's album's mbid. I am doing the following lookup using ISRC code.
https://musicbrainz.org/ws/2/isrc/USRC11600201?fmt=json
But in response I don't get any metadata related to the album of the track. I get the following response:
{
"isrc": "USRC11600201",
"recordings": [
{
"disambiguation": "single remix",
"title": "Cheap Thrills",
"id": "92e27a47-3546-4bc2-a9f7-b19e43d7a531",
"length": 223000,
"video": false
},
{
"length": 218540,
"video": false,
"title": "Cheap Thrills",
"disambiguation": "",
"id": "5845e975-33b4-4b0d-8e74-8f57d128b3d1"
}
]
}
I have tried various combinations of the "inc" sub query parameter as well but nothing works. Please help me out. I am really stuck at this.
Using inc=releases in the URL parameters should be enough to get you the information that you want. However, it seems like there's a bug with MusicBrainz's JSON web service (which is still officially in beta), as you can see in the difference between the XML and JSON end points' output:
https://musicbrainz.org/ws/2/isrc/USRC11600201?inc=releases&fmt=json (JSON) vs. https://musicbrainz.org/ws/2/isrc/USRC11600201?inc=releases (XML).
One obvious solution/work-around here would be to switch to using the more mature XML endpoint. If that is not an option, you can use the Recording MBIDs given in the JSON output to look up releases associated with those Recordings, e.g., https://musicbrainz.org/ws/2/recording/5845e975-33b4-4b0d-8e74-8f57d128b3d1?inc=releases&fmt=json (note that inc=releases is also needed here to get the information about the releases, and it actually works when looking up recordings).
So to get the details of the album of a track when I have the ISRC of the track, we need to do the following get request:
https://musicbrainz.org/ws/2/isrc/GBUM71604605?inc=releases
It will give a response in xml. The xml api is more stable click for more details on this
As I need the response in json, we can use a library like xml to json and vice-versa library
As much as I have seen the xml response from the MusicBrainz api is more accurate and gives a lot of information.