Forum Discussion
Getting the content (links and embedded object from Pages in Notebook on Sharepoint )
I was able to retrieve the content from a page in a Notebook on Sharepoint (via the content_url). After parsing the html page, I extracted the text from the page, and urls from (a href) and embedded objects (object data-attachment - via data attribute).
I make a request.get to the URL and pass in the valid token (with all the API Permissions set) but I still get a 401 error.
link URLS :
- teams.microsoft.com/file/blabhlbh&filetype=xlsx&objectUrl=https://domain.sharepoint.com/sites/sitename...
- https://domain.share.point.com/:w:s/sites/[blahblahblah
embedded objects URL :
- https://graph.microsoft.com/v1.0/siteCollections/domain.sharepoint.com,blahbha,onenote/resources/id/$value
I would like to retrieve the byte content of these documents. Is there a way to retrieve these attachments or links via their url.
2 Replies
- aymieeBrass Contributor
@Kidd_lp
I have set Read/Write/Full permission for Sites and Teams and Notebook. I can even copy the link and open it up in a browser. I just get a 401 when using request.get(url, token).
I had to go through a long process of using the graph api to test if I can get the content:
await client.drives.by_drive_id('drive-id').items.by_drive_item_id("drive-item-id").content.get()
but this is not desireable as I have the URL via the original call to client.sites.by_site_id(site_id).onenote.pages
Apparently the url I have is the Sharepoint sharing URL meant for use in a browser.
'https://domain.sharepoint.com/:w:/s/it/blahblahblah' Was hoping for a way to map this link to the drive item ID.
Edit: In case anyone has the same issue:
I was able to get the file name and retrieve the content from the "OneNote Uploads" folder:file_path = f'/{folder_name}/{file_name}'url = f'https://graph.microsoft.com/v1.0/sites/{site_id}/drive/root:/{file_path}:/content'
Thank you.