This topic was automatically generated from Slack. You can find the original thread here.
Hi I am trying to create a new workflow with:
Trigger step: when a new email is labelled in gmail with “xyz”
Download attachment from that email
Upload it to Google Drive folder
The issue is that while step 1 works, I then pass on in step 2 the path to the message id, ie: “{{steps.trigger.event.messages[0].id}}” to identify the email from which I want to download the attachment, but this results in no attachment found and when I try to select the attachment id I get “Invalid ID value”
Can you please provide guidelines on how to trouybleshoot this and make it work?
Based on your description, it seems like you’ve successfully set up the trigger for when a new email is labeled in Gmail with “xyz”. For the subsequent steps, you’ll need to ensure you’re using the correct identifiers and making the right API calls to download the attachment from the email and then upload it to Google Drive. Here’s a step-by-step guide to troubleshoot and set up the workflow: 1. Verify the Message ID: Ensure that the message ID you’re using in step 2 is correct. The placeholder {{steps.trigger.event.messages[0].id}} should indeed give you the message ID of the first email that triggered the workflow. If this is resulting in an “Invalid ID value” error, double-check the trigger data to make sure the message ID is being passed correctly. 2. Download the Attachment: Once you have the correct message ID, you’ll need to use the Gmail API to fetch the details of the message, which includes the attachment’s part ID. You can then use this part ID to download the attachment. Here’s an example of how you might write the component to download the attachment: ``` import { axios } from “@pipedream/platform”; export default defineComponent({ props: { gmail: { type: “app”, app: “gmail”, }, }, async run({ steps, $ }) { // Fetch the message details using the message ID const messageDetails = await axios($, { url: https://gmail.googleapis.com/gmail/v1/users/me/messages/${steps.trigger.event.messages[0].id}, headers: { Authorization: Bearer ${this.gmail.$auth.oauth_access_token}, }, }); // Find the part ID of the attachment const partId = messageDetails.data.payload.parts.find(part => part.filename).body.attachmentId; // Download the attachment const attachment = await axios($, { url: https://gmail.googleapis.com/gmail/v1/users/me/messages/${steps.trigger.event.messages[0].id}/attachments/${partId}, headers: { Authorization: Bearer ${this.gmail.$auth.oauth_access_token}, }, }); // The attachment content will be base64 encoded, so you may need to decode it const attachmentData = Buffer.from(attachment.data.data, ‘base64’); // Return the attachment data for the next step return attachmentData;
It’s most likely a bug because when I select the same email from the list it works and I can download its attachment but when I use the path to the email id from the trigger step it fails, anyone else had this issue?
I guess I can always write a code block to retrieve the attachment using an api access and some js or python code, but it really seems that something’s off here, this action seems intended to download attachment and it “feels” like something pretty basic a out of the box building block should be able to do…
if in step 2 I simply select one email, then the next config step where I should select the attachment id works fine I get a list to choose from manually, but ofc that doesn’t help me create a dynamic workflow