How can I get an attachment from an email?

To get an attachment from an email with Nylas API v3, you need to first find the attachment ID, then either get its metadata or download it.

Find the attachment ID

curl -L 'https://api.us.nylas.com/v3/grants/<NYLAS_GRANT_ID>/messages/<MESSAGE_ID>?select=attachments' \
-H 'Authorization: Bearer <NYLAS_API_KEY>'

This returns the attachments with their IDs.

Get attachment metadata

Use the Return Attachment Metadata endpoint to get information about a specific attachment

curl --request GET \
--url 'https://api.us.nylas.com/v3/grants/<NYLAS_GRANT_ID>/attachments/<ATTACHMENT_ID>?message_id=<MESSAGE_ID>' \
--header 'Accept: application/json, application/gzip' \
--header 'Authorization: Bearer <NYLAS_API_KEY>'

Download the attachment

curl --request GET \
--url 'https://api.us.nylas.com/v3/grants/<NYLAS_GRANT_ID>/attachments/<ATTACHMENT_ID>/download?message_id=<MESSAGE_ID>' \
--header 'Authorization: Bearer <NYLAS_API_KEY>'

Search for messages with attachments

You can also search for messages that have attachments using the has_attachment query parameter.

curl 'https://api.us.nylas.com/v3/grants/<NYLAS_GRANT_ID>/messages?has_attachment=true'

This returns only messages that include attachments, making it easier to find the files you want to work with

Resources

Using the Attachments API

Parsing messages in Nylas

Searching with Nylas

 

 

Updated

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.