obtain item-id for microsoft graph api - sharepoint

I am trying to figure out how to obtain an "item-id" for a file in a sharepoint site for microsoft graph API.
Microsoft documentation: https://learn.microsoft.com/en-us/graph/api/driveitem-get?view=graph-rest-1.0&tabs=http
Here is what I tried for far:
Tried using https://developer.microsoft.com/en-us/graph/graph-explorer to guess the api link that will let me download the file I want.
I first tried to get the sharepointsite like so:
https://graph.microsoft.com/v1.0/sites/omidtechnfr.sharepoint.com:/sites/delploy
That worked:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites/$entity",
"createdDateTime": "2021-07-15T21:02:02.78Z",
"description": "delploy",
"id": "omidtechnfr.sharepoint.com,5e03397e-03b0-4d92-9658-f9163f0131b3,1d9f21da-4d74-45db-b5d4-e4a7f7f278a1",
"lastModifiedDateTime": "2021-07-17T02:16:39Z",
"name": "delploy",
"webUrl": "https://omidtechnfr.sharepoint.com/sites/delploy",
"displayName": "delploy",
"root": {},
"siteCollection": {
"hostname": "omidtechnfr.sharepoint.com"
}
}
So then I tried using what I ASSUME is the item-id for the SharePoint site delploy to try and get more information out of the site so I can try to find the item-id for the file I want to download:
https://graph.microsoft.com/v1.0/sites/5e03397e-03b0-4d92-9658-f9163f0131b3/drive/
And I got back some result but it doesn't so the item-id for me to do anything with it:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives/$entity",
"createdDateTime": "2021-07-11T05:16:50Z",
"description": "",
"id": "b!fjkDXrADkk2WWPkWPwExs9ohnx10TdtFtdTkp_fyeKF_K1_Z49FFSbzXVFRA5GKa",
"lastModifiedDateTime": "2021-07-16T18:32:35Z",
"name": "Documents",
"webUrl": "https://omidtechnfr.sharepoint.com/sites/delploy/Shared%20Documents",
"driveType": "documentLibrary",
"createdBy": {
"user": {
"displayName": "System Account"
}
}
At this point I started to get desperate and a little angry. So I tried to just download the file from sharepoint and assume that the characters at the end of the download link was the item-id but that didn't work either:
download link:
https://omidtechnfr.sharepoint.com/sites/delploy/_layouts/15/download.aspx?UniqueId=25e2fd4f%2Deb32%2D43ac%2D9141%2Dfa47a610a27c
Used https://www.urldecoder.org/ to decode what I am assuming is the item-id for the file I want to download
25e2fd4f-eb32-43ac-9141-fa47a610a27c
Then tried to desperately tack this on to the Microsoft graph api to see what happens:
https://graph.microsoft.com/v1.0/sites/5e03397e-03b0-4d92-9658-f9163f0131b3/drive/items/25e2fd4f-eb32-43ac-9141-fa47a610a27c
and it failed:
{
"error": {
"code": "itemNotFound",
"message": "The resource could not be found.",
"innerError": {
"date": "2021-07-17T14:13:51",
"request-id": "985e2893-5343-47ac-a93c-6629a00c4eb3",
"client-request-id": "73a3b6d0-f1ce-bb51-b126-43f0957d15e3"
}
}
}

You could get the file by the path: https://graph.microsoft.com/v1.0/sites/{site-id}/drive/root:/{item-path}
For example: https://graph.microsoft.com/v1.0/sites/{site-id}/drive/root:/test.docx
If the file is in a folder, it would be like this: https://graph.microsoft.com/v1.0/sites/{site-id}/drive/root:/folder1/test.docx

I used the search site id endpoint GET /sites/{site-id}/drive/root/search(q='{search-text}')
Documentation here.

Related

Microsoft Graph Search 400 error when searching

I'm getting a 400 error when trying to do a search both through the Graph Explorer and through my own code. Both worked a few weeks ago but have stopped working recently. Another developer has been able to replicate it in their Tenancy, but Microsoft will not provide me support as we are not a Premier Customer.
If I run this query:
https://graph.microsoft.com/v1.0/drives{drive_id}/root/
it succeeds and returns information about the drive.
Following the documentation at https://learn.microsoft.com/en-us/graph/api/driveitem-search?view=graph-rest-1.0&tabs=http a search can be used via
https://graph.microsoft.com/v1.0/drives/{drive-id}/root/search(q='foobar')
But this returns a 400 error with "One of the provided arguments is not acceptable."
However, if I search for items in our entire Tenancy via the group search it succeeds so it doesn't appear to be a permissions error, but is not a viable solution as I need to search a particular drive.
please confirm whether you are still facing the issue. I was not able to reproduce the same from my side.
I ran this query:
https://graph.microsoft.com/v1.0/me/drives/drive-id/root/Search(q='Practices Checker')
And was able to get the desired result as below:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)",
"value": [
{
"#odata.type": "#microsoft.graph.driveItem",
"createdDateTime": "2020-12-09T11:55:47Z",
"id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"lastModifiedDateTime": "2020-11-03T06:51:27Z",
"name": "Practices Checker",
"webUrl": "https://microsoftapc-my.sharepoint.com/personal/ribera_xxxxxxxx_com/Documents/Documents/Practices%20Checker",
"size": 0,
"createdBy": {
"user": {
"email": "ribera#xxxxxxxxxx.com",
"displayName": "Rinki Bera"
}
},
"lastModifiedBy": {
"user": {
"email": "ribera#xxxxxxxxxx.com",
"displayName": "Rinki Bera"
}
},
...
]
}
Thank you.

Microsoft GraphAPI and Sharepoint : List shared files

So I am not sure where I am going wrong but here goes!
I want to list files on my test Sharepoint site via the MS GraphAPI. This via the documentation should be simple but it's just not happening!
I am using the GraphAPI explorer
https://developer.microsoft.com/en-us/graph/graph-explorer/preview
I then can see my site and its shared folder via this call
https://graph.microsoft.com/v1.0/sites/MyCompany.sharepoint.com:/sites/burf-test:/drive
I get back:
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives/$entity",
"createdDateTime": "2020-04-19T05:47:58Z",
"description": "",
"id": "b!BWveRisE5UWH2b_vq03PZYmZdMdKpQtFhpIQSacsCowq3ZxYLFsFQKtzuZ4-V1ya",
"lastModifiedDateTime": "2020-04-30T13:50:28Z",
"name": "Documents",
"webUrl": "https://-.sharepoint.com/sites/Burf-Test/Shared%20Documents",
"driveType": "documentLibrary",
"createdBy": {
"user": {
"displayName": "System Account"
}
},
"owner": {
"group": {
"email": "Burf-Test#-.onmicrosoft.com",
"id": "e48afefa-2aa8-4cd5-aad9-62f746a991c2",
"displayName": "Burf-Test Owners"
}
},
"quota": {
"deleted": 0,
"remaining": 0,
"total": 0,
"used": 0
}
}
I can not find a way to list the files that I can see via my Sharepoint portal (Burf-Test)?
Tried
/drive/root/children
/drive/b!BWveRisE5UWH2b_vq03PZYmZdMdKpQtFhpIQSacsCowq3ZxYLFsFQKtzuZ4-V1ya
/drives/b!BWveRisE5UWH2b_vq03PZYmZdMdKpQtFhpIQSacsCowq3ZxYLFsFQKtzuZ4-V1ya
/drive/Documents
/lists etc
and a whole lot more!
So the main issue here was actually permissions, sometimes the Graph Explorer will say Access denied, and sometimes it will return a 200 but not show the files. Both mean a permissions issue.
I found I had to grant extra permissions (File ones) to get this to work
https://graph.microsoft.com/v1.0/sites/a-.sharepoint.com,SITE-GUID/drives/FOLDER-GUID/root/children

How to get the Site Id of SharePoint using Graph SharePoint Explorer

How to get the Microsoft SharePoint SiteID using Microsoft Graph API Explorer.
Initially i tried with below API i able to get the Site ID
https://graph.microsoft.com/v1.0/sites/tenantName.sharepoint.com:/sites/TestSite:/drives?select=name,id
Sharepoint URL:
https://tenantName.sharepoint.com/sites/TestSite
I output i got is:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives",
"value": [
{
"id": "b!l17-JY9YT67Qp-2TBvsUupBLMUF2SrJHp5VylCDZThT7HpCdF-7uQ6NTp6t-MbR5",
"name": "Documents"
}
]
}
But, when i try with Communication Site
Whose SharePoint URL is:
https://tenantName.sharepoint.com/SitePages/DevHome.aspx
Graph Explorer API
https://graph.microsoft.com/v1.0/sites/tenantName.sharepoint.com:/SitePages/DevHome:/drives?select=name,id
I am getting below error:
{
"error": {
"code": "itemNotFound",
"message": "The provided path does not exist, or does not represent a site",
"innerError": {
"request-id": "8329dfca-c63b-4af5-80b8-75f26be9e2e8",
"date": "2019-10-31T13:18:33"
}
}
}
A sitePage is a fundamentally different resource than a site.
A site is a container that owns any number of sub-sites, apps, lists, document libraries, etc.
A sitePage is just another resource owned by a site.
The sitePage resource is currently only available in the Microsoft Graph Beta version.
So the query for /SitePages/DevHome.aspx would be:
/beta/sites/root/pages/{pageId}
If you don't yet know the correct id for the page, you can filter the SitePage collection based on the page's name:
/beta/sites/root/pages?$filter=name eq 'DevHome.aspx'
This will return a collection with a single entity (the DevHome.aspx page):
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#sites('root')/pages",
"value": [
{
"eTag": "",
"id": "{id}",
"lastModifiedDateTime": "2014-07-10T05:47:29Z",
"name": "DevHome.aspx",
"webUrl": "SitePages/DevHome.aspx",
"createdBy": {
"user": {
"displayName": "System Account"
}
},
"lastModifiedBy": {
"user": {
"displayName": "System Account"
}
},
"parentReference": {
"siteId": "{id}"
},
"contentType": {
"id": "0x0101080062C83F3CFED6744A882F729480DE6C17",
"name": "Wiki Page"
},
"webParts": [],
"publishingState": {
"level": "published",
"versionId": "1.0"
}
}
]
}
I should also point out that you're misinterpreting the result of your first query. When you request /v1.0/sites/{tenant}:/{path}:/drives?select=name,id, you are not getting the IDs for each Site, you're getting the IDs for each Drive within that Site. You can find the objects contained within a site in the Relationships section of the Site Resource documentation
Your Graph API call is incorrect.
Try this one :
https://graph.microsoft.com/v1.0/sites/tenantName.sharepoint.com?select=name,id

MS Graph API access to a workbook from a driveItem

I have written some code which successfully accesses an excel spreadsheet on a sharepoint site. I did this by finding the driveid in graph explorer then browsed to find the workbook item and worksheet.
Now I need to do the same thing but I can't use Graph Explorer to find the drive ID so I understood that I could generate the drive id using the method shown at https://www.techmikael.com/2018/07/using-microsoft-graph-to-get-pdf.html
( Side-note, my node.js version of the same code is at https://glitch.com/~ultra-sloop )
From this URL :
https://alphaindigo.sharepoint.com/:x:/r/_layouts/15/Doc.aspx?sourcedoc=%7B1F4C6E80-0A55-4717-8D8D-19382F8E3C69%7D&file=Buddies.xlsx&action=default&mobileredirect=true
I generate this one.
https://graph.microsoft.com/v1.0/shares/u!aHR0cHM6Ly9hbHBoYWluZGlnby5zaGFyZXBvaW50LmNvbS86eDovci9fbGF5b3V0cy8xNS9Eb2MuYXNweD9zb3VyY2Vkb2M9JTdCMUY0QzZFODAtMEE1NS00NzE3LThEOEQtMTkzODJGOEUzQzY5JTdE/driveitem
When I run this in Graph Explorer as a test, it gives me the details of the driveItem, like this :
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#shares('u%21aHR0cHM6Ly9hbHBoYWluZGlnby5zaGFyZXBvaW50LmNvbS86eDovci9fbGF5b3V0cy8xNS9Eb2MuYXNweD9zb3VyY2Vkb2M9JTdCMUY0QzZFODAtMEE1NS00NzE3LThEOEQtMTkzODJGOEUzQzY5JTdE')/driveItem/$entity",
"#microsoft.graph.downloadUrl": "https://alphaindigo.sharepoint.com/_layouts/15/download.aspx?UniqueId=1f4c6e80-0a55-4717-8d8d-19382f8e3c69&Translate=false&tempauth=eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAvYWxwaGFpbmRpZ28uc2hhcmVwb2ludC5jb21AMGQ3NTY1NzUtMjgwOC00NmE1LWIyYmEtMDFlZTgzZmIwZTEzIiwiaXNzIjoiMDAwMDAwMDMtMDAwMC0wZmYxLWNlMDAtMDAwMDAwMDAwMDAwIiwibmJmIjoiMTU2Mjg5MzAyNSIsImV4cCI6IjE1NjI4OTY2MjUiLCJlbmRwb2ludHVybCI6InNzeDk3QjhPRk1mTXVTS1NyK2M5dFpITWtsdi9yR1BUbWdEL2hnSlhDVTQ9IiwiZW5kcG9pbnR1cmxMZW5ndGgiOiIxMjIiLCJpc2xvb3BiYWNrIjoiVHJ1ZSIsImNpZCI6Ik5qWTNPRFl4WTJNdE4yWXpNeTAwWTJFd0xUbGhaV1l0WkRnM05ERXpOV05sTW1GaSIsInZlciI6Imhhc2hlZHByb29mdG9rZW4iLCJzaXRlaWQiOiJORGM1TURWaE4yUXRObUl5TXkwME5EUTRMV0ZtWkdRdE5UVTJZamcwWlRNNFpUSmoiLCJhcHBfZGlzcGxheW5hbWUiOiJHcmFwaCBleHBsb3JlciIsInNpZ25pbl9zdGF0ZSI6IltcImttc2lcIl0iLCJhcHBpZCI6ImRlOGJjOGI1LWQ5ZjktNDhiMS1hOGFkLWI3NDhkYTcyNTA2NCIsInRpZCI6IjBkNzU2NTc1LTI4MDgtNDZhNS1iMmJhLTAxZWU4M2ZiMGUxMyIsInVwbiI6ImRvdWdAYWxwaGFpbmRpZ28ub25taWNyb3NvZnQuY29tIiwicHVpZCI6IjEwMDMyMDAwNDZDREY4QzQiLCJjYWNoZWtleSI6IjBoLmZ8bWVtYmVyc2hpcHwxMDAzMjAwMDQ2Y2RmOGM0QGxpdmUuY29tIiwic2NwIjoibXlmaWxlcy5yZWFkIGFsbGZpbGVzLnJlYWQgbXlmaWxlcy53cml0ZSBhbGxmaWxlcy53cml0ZSBhbGxzaXRlcy5yZWFkIGFsbHNpdGVzLndyaXRlIiwidHQiOiIyIiwidXNlUGVyc2lzdGVudENvb2tpZSI6bnVsbH0.L2t4YmRDQlpwS2dGMjIvdmxoVFA5ZXA0Qyt0b3VWWE9rb0h1UTJzcFVHRT0&ApiVersion=2.0",
"createdDateTime": "2019-05-05T04:52:56Z",
"eTag": "\"{1F4C6E80-0A55-4717-8D8D-19382F8E3C69},688\"",
"id": "01FQPFGAEANZGB6VIKC5DY3DIZHAXY4PDJ",
"lastModifiedDateTime": "2019-06-29T02:24:23Z",
"name": "Buddies.xlsx",
"webUrl": "https://alphaindigo.sharepoint.com/_layouts/15/Doc.aspx?sourcedoc=%7B1F4C6E80-0A55-4717-8D8D-19382F8E3C69%7D&file=Buddies.xlsx&action=default&mobileredirect=true",
"cTag": "\"c:{1F4C6E80-0A55-4717-8D8D-19382F8E3C69},690\"",
"size": 31938,
"createdBy": {
etc etc...
but when i attach /workbook/worksheet/file-name to the end
https://graph.microsoft.com/v1.0/shares/u!aHR0cHM6Ly9hbHBoYWluZGlnby5zaGFyZXBvaW50LmNvbS86eDovci9fbGF5b3V0cy8xNS9Eb2MuYXNweD9zb3VyY2Vkb2M9JTdCMUY0QzZFODAtMEE1NS00NzE3LThEOEQtMTkzODJGOEUzQzY5JTdE/driveitem/workbook/worksheets('Sheet1')/range(address='A1:D4')
I get this error :
"error": {
"code": "InternalServerError",
"message": "Unable to find target address",
"innerError": {
"request-id": "5bea4b7f-91d9-4ba6-a26f-7964a4122a0a",
"date": "2019-07-12T00:36:16"
}
}
}
If I step back from there, dropping the worksheet name and range using this :
https://graph.microsoft.com/v1.0/shares/u!aHR0cHM6Ly9hbHBoYWluZGlnby5zaGFyZXBvaW50LmNvbS86eDovci9fbGF5b3V0cy8xNS9Eb2MuYXNweD9zb3VyY2Vkb2M9JTdCMUY0QzZFODAtMEE1NS00NzE3LThEOEQtMTkzODJGOEUzQzY5JTdE/driveitem/workbook
I get the same error
A similar issue is already listed, answered at
Pulling Excel.xlsx workbook from Sharepoint site using Microsoft Graph API
but as I already have a driveItem rather than a listItem it does not answer my issue.
A workaournd:
json_response = GET("https://graph.microsoft.com/v1.0/shares/u!aHR0cHM6Ly9hbHBoYWluZGlnby5zaGFyZXBvaW50LmNvbS86eDovci9fbGF5b3V0cy8xNS9Eb2MuYXNweD9zb3VyY2Vkb2M9JTdCMUY0QzZFODAtMEE1NS00NzE3LThEOEQtMTkzODJGOEUzQzY5JTdE/driveitem")
drive_item = json_response["id"]
drive = json_response["parentReference"]["driveId"]
print(GET("https://graph.microsoft.com/v1.0/me/drives/{drive}/items/{drive_item}/workbook"))

Azure Cognitive Services - Batch Transcription API responds with error message "The recording URI is invalid."

Steps Followed:
I created a speech services instance in West US.
I have the right headers(Content-Type and Ocp-Apim-Subscription-Key)
I make a POST request to https://westus.cris.ai/api/speechtotext/v2.0/transcriptions/ with below request payload
{
"recordingsUrl": "https://transcribehm97c1.blob.core.windows.net/audio-files/2019-04-04_Blockchain%20explained%20with%20TruStory%27s%20Preethi%20Kasireddy.mp3?st=2019-05-27T12%3A19%3A27Z&se=2019-12-31T12%3A19%3A00Z&sp=rl&sv=2018-03-28&sr=b&sig=HFBvGl1pmCM95MNU9U3yniMNXrUMT6RmPb36F32cxrY%3D",
"models": [],
"locale": "en-US",
"name": "I dont know why this is not working",
"description": "Someone please send help",
"properties": {
"ProfanityFilterMode": "Masked",
"PunctuationMode": "DictatedAndAutomatic"
}
}
I get a “202 Accepted” response with below headers. This confirms that the request body is valid.
location: https://westus.cris.ai/api/speechtotext/v2.0/transcriptions/69b7abf4-6383-4490-88a9-9fd42a77e470
When I make a GET Request to the above location, I see this
{
"recordingsUrl": "https://transcribehm97c1.blob.core.windows.net/audio-files/2019-04-04_Blockchain explained with TruStory's Preethi Kasireddy.mp3?st=2019-05-27T12:19:27Z&se=2019-12-31T12:19:00Z&sp=rl&sv=2018-03-28&sr=b&sig=HFBvGl1pmCM95MNU9U3yniMNXrUMT6RmPb36F32cxrY%3D",
"resultsUrls": {},
"models": [“I have removed this for brevity”],
"statusMessage": "The recordings URI is invalid.",
"id": "69b7abf4-6383-4490-88a9-9fd42a77e470",
"createdDateTime": "2019-05-27T12:43:39Z",
"lastActionDateTime": "2019-05-27T12:43:50Z",
"status": "Failed",
"locale": "en-US",
"name": "I dont know why this is not working",
"description": "Someone please send help",
"properties": {
"ProfanityFilterMode": "Masked",
"PunctuationMode": "DictatedAndAutomatic"
}
}
The transcriptions fails for some URL's while passing for others for blobs in the same storage although they are all valid URL’s. The SAS URI in the request is valid till end of the
year.
I have re-tried the same request multiple times via code and Postman and it fails.
Link to Swagger Page : https://westus.cris.ai/swagger/ui/index
The issue may be due to the audio file size. Please refer the core features for REST API as the REST support only short Audio.

Resources