Extract 'from', 'subject' and 'text' from Gmail Trigger

I have the Gmail Trigger in JSON, but I only need the ‘from’, ‘subject’ and ‘text’. So I use a Code node to extract those 3 items, how can I write a Python code to achieve it?

hello @TH1

why you need a python or a code node? You can use the Edit Fields node and assign whatever fields you need in it

1 Like

oh, thanks for your good suggestion. so this shows I am really a big DUMMY in n8n, need all the expertise guidance here. thanks a lot.

// Extract email body from Gmail data (simple mode disabled)
const items = $input.all();
const results = [];

for (const item of items) {
  const emailData = item.json;
  
  // With simple: false, Gmail provides the text field with the full email body
  const emailBody = emailData.text || emailData.html || '';
  
  results.push({
    json: {
      emailBody: emailBody
    }
  });
}

return results;

I know this has already been answered, but just for anyone else, I ran into a similar issue where I only needed the email body from the gmail-trigger. Above was my solution in a code node ^^^

You could modify it to only pick the fields you want.. BUT AGAIN it looks like the Edit Fields node was the correct solution

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.