Download files shared on public channel on teams using api - microsoft-graph-api

I am using microsoft teams API to fetch public channel message. With messages I also get attachments with a sharepoint URL as content URL. Now I want to download that file but it fails to download it. If I directly copy paste contentURL on browser, it downloads the file but if I do an http call, it fails. I cannot use sharepoint graph api(download by item ID) as I don't get itemID here. Is there any way to download those file? Any permission needed or any mistake I am doing on HTTP call?
PS: I do see a couple of same questions but there are no accepted answer and all are couple of years old.

Related

Can a Slack bot re-share a file that was shared with it?

Context of what I'm trying to accomplish:
User shares a file with the bot
Other users interact with the bot via a dialog
The bot shares the original file to the other users
For example, we want to share a file to the bot that contains this week's cafeteria menu. Each time users would interact with the bot in a certain way, it would share the cafeteria menu with them so that they can consult it.
I've tried calling files.share method but bots can't perform this action (get invalid token type error).
As far as I can tell, there is no way to do this currently. I've tried link unfurling in the message body but that only works if the file itself was already shared to the user. If not, the link simply won't unfurl and clicking it will fail.
The bot can perform a files.upload call and re-upload the contents of the file to each user individually. This seems incredibly wasteful but appears to be the only way to work currently.
Is there something I'm missing?
The reason your bot can not use file.share is that this is an undocumented API method and you need a legacy token to use it. No other token (user token, bot token) will work, because it requires the post scope, which only exists for legacy token.
Approach A: Legacy Token
So one approach would be to use a legacy token with your bot, which you can create here for your current workspace. That should work nicely if your Slack app is only used on your "own" Slack workspace where you can create and use a legacy token.
Approach B: File Mention
Another approach is to use the mention feature in messages to share a file. This works by sending the private link (url_private property) of an already shared file in a message to a new channel. This will automatically re-share the file in that channel. I believe this only works with files that how been previously shares in a public channel and can therefore be re-shared. Be aware though that the file mention feature is currently being reworked, so this behavior might change.
Example:
https://slack.com/api/chat.postMessage?token=TOKEN&channel=CHANNEL&as_user=true&text=URL_PRIVATE
For more details see the Slack tutorial Storing, retrieving, and modifying file uploads.
Approach C: External File / image file
If you host your file externally or create a public URL for a file uploaded to Slack you can share it in every channel by just adding the URL to a message. Slack will automatically unfurl it and therefore share it to the user in any channel. This is different to Approach B, because its not a file mention and requires a public URL. You get the public URL of an uploaded file by calling files.sharedPublicURL.
If i'm not wrong, you can do like this :
you share a file with your bot
you retrieve the file shared ID, so his url_private property (cf https://api.slack.com/types/file#authentication)
you then donwload the file
you can then re-share it several times later (without re-uploading to each user)...

Outlook Rest API: Download the email attachments of type .eml files using outlook rest API

I followed this documentation to download the attachments of email.
Below is the API response.
If email attachment type is FileAttachment, I am able to get the file content in api response and able to save the attachment.
If email attachment type is ItemAttachment, I am not able to get the file content in api response. When I googled for it, I found this stack overflow question. I used the rest API mentioned in the answer. But it's giving itemAttachment content in html format. And if that ItemAttachment has any fileattachment in it, then I am unable to access it.
Is there any API available to download the itemAttachment as .eml file not as html?
Any suggestion/answers would be more than welcome.
I assume by .eml you mean you'd like to retrieve the email in MIME format?
Retrieving an email's raw MIME content isn't supported by Microsoft Graph API at this time. This has been a common request and there is an existing UserVoice request for it.
If this is a hard requirement for your scenario, you may want to take a look at Exchange Web Services (EWS). The Message object returned by EWS includes a MimeContent property.
This is now supported on https://outlook.office365.com/api/v2.0/me/messages/<Message-Id>/$value endpoint

How to get a temporary (or permanent) regular URL for a file in OneDrive using the Microsoft Graph API

Using createLink, for example with the POST parameters: {"type": "view", "scope": "anonymous"}, you get a response including a webUrl which will open the item (in read-only or read-write mode, depending on the POST parameters) in Office Online. Because of the 'anonymous' scope, anyone (no login required) can open the office online page.
Unfortunately, I don't a link to Office Online, and it looks like this is the functionality provided by Create a sharing link for a DriveItem.
I need a link to the actual file (to download it).
Something like many other 'files' APIs allow. This is, generate a time-limited (or permanent) URL to file.
Is this possible?
EDIT: Clarification: Download the contents of a DriveItem (i.e. a Stream) is not what I'm looking for.
There are four ways of linking to a file in OneDrive via Microsoft Graph:
The web preview for the file, which is accessed from the webUrl property of DriveItem. This requires the user to be signed in to access.
The WebDAV URL for the file, which is accessed from the webDavUrl property of DriveItem. This also requires the user to be signed in to access, but is a direct link to the file. Note: this is available via Microsoft Graph, but is only documented on dev.onedrive.com.
Creating a sharing link, which provides anonymous or organization restricted access to the web preview of the file.
Download link, which is a short-duration URL available to download the contents of the file programmatically.
It sounds like webDavUrl might be the link you are looking for.

How can I download a OneDrive file with Office365 REST API into a Ruby variable?

I'm building a Ruby on Rails app, and I'd like to integrate some Office365 features.
For instance : I would like to download a file from OneDrive and then attach it to an Email in order to send it via Outlook rest API.
I found this get Item content OneDrive REST API but I dont understand how to use it.
I understand that I have to send a GET request (formated as explained in msdn.microsoft.com) with Rails, which will then provide me a "a pre-authenticated download URL" to download the file.
Then I will have to send a second GET request with this a pre-authenticated download URL to start the download, but I don't understand how to deal with the Response in order to save the file into a variable.
How can I retrieve the file into a variable of my Ruby on Rails App, so that I can attach it to an Email with an Outlook REST API to send it from my own Rail controller ?
Also this workflow is really not optimized in term of Bandwidth and Processing (3 REST API request + 1 download + 1 upload), it will work.
However if it exist a single REST API that direclty attach a OneDrive file to an email to send it, that would ease a lot my life, save energy, save money from Microsoft datacenter, and spare the planet ecology.
Any tutorial, examples, or more explanatory doc would be much appreciated.
--- EDIT ---
Adding link to the email is not wished as the email may have to be send to someone outside of Office365 users, and public link are a security issue for confidential documents.
Any help is welcome.
There isn't a single REST API call you can make currently to do what you want, although being able to easily attach a file from OneDrive to a new email message is a great scenario for Microsoft Graph API, it just isn't supported right now.
If you want to attach the file, you need to do as you mentioned, download the contents of the file, and then upload it again as an attachment to the message.
However, I'd recommend sending a link to the file instead, even though you mentioned you don't want to do that. OneDrive for Business now supports "company shareable links" which are scoped to just the user's organization instead of being available totally anonymously.
Something else to consider: The security concerns of sending an anonymous link aren't that different than sending an attached file. In fact, the anonymous link can be more secure, because access to the file can be monitored and revoked in the future (unlike the attachment, which will always be out there).

Using Dailymotion API to retrieve Video IDs

I am trying to make a certain request work via the Dailymotion API, for work. Our client is a Dailymotion Partner who asked us to do 2 things from our application :
Generate a XML file to MRSS-upload their videos on Dailymotion (but we do not do the actual uploading, only the XML file creation)
Later, once they have uploaded their video, we have to get its Dailymotion ID (for logs necessities).
The thing is that this process has been developed circa 2012, and not fully tested. My job today is to make sure the process works now for good. In order to get the ID, we have been using this request:
https://api.dailymotion.com/video/PARTNER_NAME:GUID?fields=id
but I can't find any mention of "partner" and "guid" in the Dailymotion Documentation today. All I know is that we use the name of the channel as PARTNER_NAME and the guid we put in the XML file as GUID.
The thing I don't understand is that:
sometimes, the request does succeed and I get the ID,
most of the time, I get alternatively "400" and "403" errors from the API.
First, I tried to set the attribute "private" in the XML file to 'false', and it helped get the ID of some videos imported as public, but it does not do the trick for all videos.
Could someone show some light on this matter?

Resources