The above code is based on the assumption that there is only one pdf attachment. But I think it could be easily extended with other criteria, like filename.
Sharing this as it took me a while to figure out how to get to the right attachment (i.e. the one I needed to act upon).
Interested to read if there are other (better!) solutions.
For multiple files in the attachments I was able to recreate the data structure to convert the single array to multiple based on number of attachments are there, the main issue I faced generally was that one to many relation was creating problem as there I was having to use static index and not dynamic. so here is my code which takes email data and create new object corresponding to each attachment.
If you need one attachment per item then what you posted is a viable way to do that. I would then however not name them again attachment_<INDEX> I would rather choose either data or attachment to make it then easy to use in the following nodes.
Aha, Okay, understand your point. But what confused me was this:
When we look at result on the node/module it lists the binary data in same tab as 1,2 and so on so I think that confused me. But now I understand, if i name it data and because it is with per-attachment per json object it’ll be fine to use data. Did I understand correctly ?