How to update an Airtable Attachment field (using a file or url)

I managed to do this simply with Zapier, but I don’t understand why it doesn’t work with Pipedream.

With Zapier, I used the same URL in both an “Url” field (drawUpMinutesAsPDFDownloadUrl) and an “Attachment” field (drawUpMinutesAsPDF), and it works well.

With Pipedream, I tried different variants:

Using the Google Export url

In this case, I tried using the pattern as what I did in Zapier, but it fails with:

INVALID_ATTACHMENT_OBJECT - 422 - Invalid attachment for field drawUpMinutesAsPDF: parameters must be objects, not strings

image|690x286

Using an object

Tried to feed a JS object with a url property to solve the above issue.

First, I create a JS object and then use it to fill drawUpMinutesAsPDF, but it fails with:

INVALID_ATTACHMENT_OBJECT - 422 - Invalid attachment object for field drawUpMinutesAsPDF

image|690x499


None of those variants worked out. I’m stuck.

P.S : Not having the ability to put more than one image and 2 links SUCKS.

Hi @dna.pc.pro, thank you for the all detailed information provided.

The Airtable API expects a list of up to 10 URLs for attachments. You can use the following code below if you want to upload just one attachment URL:

{{ [ { "url": "https://www.africau.edu/images/default/sample.pdf" } ] }}

Explanation:
The prop will load the input value as a string, so we need {{ }} to actually send it as a JS object.
Then we send a list of objects { "url": "http_url" }.

I believe you correctly tried the example above, just not encapsulated the object inside an array. Please try this out and see if it works for you!

1 Like

Thanks! I tried using an object:

image|690x96
image|690x98

But neither those two worked, I’m not sure what’s the proper syntax to use in such case.

:point_right: Eventually, I used my NodeJS code to return an array, and that worked, indeed:

Using {{steps.get_airtable_pdf_as_attachment.$return_value}} in the input.

Unfortunately, on Airtable, the Attachment is a blank page. I looked at permissions, and the file/folder are publicly available so it’s not the issue. I’ll try to download the file first instead but I’m not sure if that’ll help.

I’m not sure why it was failing, but by re-testing every step in the Draft workflow it started to work.

Awesome, happy to hear
Nice, using the Node.js step to return the array is definitely a cleaner solution

1 Like

Final solution:

// To use previous step data, pass the `steps` object to the run() function
export default defineComponent({
  async run({ steps, $ }) {
    const docId = steps.create_file_from_template.$return_value.googleDocId;
    const pdfUrl = `https://docs.google.com/feeds/download/documents/export/Export?id=${docId}&exportFormat=pdf`

    // Return an array of attachments - See https://pipedream.com/community/t/how-to-update-an-airtable-attachment-field-using-a-file-or-url/6378/2
    return {
      drawUpMinutesAsDocUrl: `https://docs.google.com/document/d/${steps.create_file_from_template.$return_value.googleDocId}/edit`,
      drawUpMinutesAsPDF: [{
        url: pdfUrl
      }]
    }
  },
})
1 Like