Hi,
I have a workflow in n8n that starts with Microsoft Teams Trigger (New Channel Message).
In the channel, users post messages with attached files (e.g., PDF).
I would like the workflow to immediately download the file and pass it to the next nodes as binary data.
Questions:
Is there a built-in way in n8n to get the attachment as binary (or at least a direct download link) from the Teams trigger?
Or what is the recommended method to fetch the file directly, without having to go through SharePoint afterward?
I have already tried using the “Get many messages” node and also made HTTP requests to the Graph API (/teams/{teamId}/channels/{channelId}/messages/{id}/attachments) but in both cases no file content appears.
Any guidance or best practices would be appreciated!
The response to .../messages/{id}/attachments should be a list of JSON “info” items, describing each attachment. If you are not finding the binary data, base64 encoded, in the content attribute of the attachment JSON item, it may instead have a value for contentUrl.
The next step would be to Split Out the list (array) of attachment “info” items and then:
If the content string isn’t null, it could be base64 encoded binary data, so use that field name (“content”) as the Base 64 Input Field in a Convert to File node, with the operation set to Move Base64 String to File.
…or… If there is a contentUrl value, use that in another HTTP Request to fetch the binary data. (Haven’t tried this… note that it could have another JSON wrapper around base64 encoded data that would need to be extracted the same way as in the content option).
You may want to first filter the attachment “info” item list based on contentType, or name to limit which attachments you try to fetch or extract. For reference, the contentType values are documented here
There is a contentUrl, but the Microsoft Teams credential is not authorized to access the resource. I also attempted using SharePoint and encountered the same error code.
I was able to solve this problem as follows:
I convert the contentURL to base64 and then use the Graph endpoint “https://graph.microsoft.com/v1.0/shares/u!{{ $json.encoded }}/driveItem/content” to download the file.
For authentication, I use the generic Microsoft Teams credential, since I had issues with the Refresh Token when using the Graph credential.