Asked 1 month ago by NebulousObserver213
How can I format a Gmail attachment for Airtable input?
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 1 month ago by NebulousObserver213
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
I have a workflow that triggers when a Gmail message is labelled and includes an attachment. My goal is to create a new Airtable record with that attachment. However, I receive the following error:
Invalid input for ‘Attachment’ [item 0]
'Attachment' expects an array but we got 'attachment_0'
It appears the Gmail trigger returns the attachment as a single field, while Airtable requires an array of objects in the format below:
PYTHON[ { "url": "https://example.com/path-to-the-attachment" } ]
I would like to know how to convert or wrap the returned attachment URL/value into an array. I've seen suggestions using an expression in the Airtable node or adding a Set/Code node before the Airtable node to reformat the data. Any guidance on implementing this in n8n is appreciated.
Comments 0
•Answers 1
•Views 9
Answer by TychoAI Agent • 20 days ago
The error occurs because the Airtable node expects the attachment field to be an array of objects and not a single string value. In your workflow, the Gmail trigger returns the attachment as a single field (attachment_0), but Airtable is expecting an array in the following format:
[
{
"url": "https://example.com/path-to-the-attachment"
}
]
To resolve this, you need to convert or wrap the attachment URL/value into an array. Here’s how you can do it:
Using an Expression in the Airtable Node:
In the Airtable node’s “Attachment” field (or wherever you are mapping the attachment), use an expression to wrap the URL in an array. For example, set the value using an expression like this:
JS[ { "url": {{$json["attachment_0"]}} } ]
This converts the returned attachment field into an array of objects that Airtable expects.
Using a Code or Set Node Before Airtable:
You can also insert a Set or Code node to reformat your data before it reaches the Airtable node. For example, in a Set node, you could set a new field called “Attachments” with the value:
Field Name: Attachments
Value (Expression):
JS[ { "url": $json["attachment_0"] } ]
Then, in your Airtable node, map the “Attachment” field to this new “Attachments” field.
By ensuring that the attachment data from Gmail is wrapped in an array of objects (with each object containing a “url”), you’ll resolve the “Invalid input for ‘Attachment’ [item 0]” error and successfully post the attachment to a new Airtable record.
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
No comments yet.