Automation Blog

How to Hydrate a File with a GET Request in a Zapier Code Step

When a Zap step produces a file URL rather than a file object — an API export URL, a signed S3 link, a PDF generation endpoint — downstream steps that need a file attachment can't always use the URL directly. Here is how to use z.dehydrateFile() to convert any GET-accessible URL into a proper Zapier file object.

ZapierCode StepsFile Automation

By Troy Tessalone · · 4 minutes

Automation Guide

A practical field guide from Automation Ace.

How to Hydrate a File with a GET Request in a Zapier Code Step

Zapier distinguishes between a file URL (a string pointing to a file) and a file object (a hydrated reference that Zapier resolves into actual file contents when a downstream step needs it). App steps that upload attachments — Gmail, Google Drive, Dropbox, Slack, and others — expect a file object in their attachment field. When your Zap produces a URL instead of a file object, a one-line Code step using z.dehydrateFile() bridges the gap. This guide explains when and how to use it.

The Problem: URL vs. File Object

Consider this scenario: an API step returns a PDF download URL. You want to attach that PDF to a Gmail message in the next step. If you map the URL string directly to Gmail's attachment field, Gmail's Zapier integration may not fetch and attach the file — it expects a file object. The solution is a Code step that converts the URL into a dehydrated file reference using z.dehydrateFile().

z.dehydrateFile(): The Core Pattern

z.dehydrateFile() accepts a URL and optional request options, and returns a dehydrated file reference. Zapier fetches the actual file contents from the URL at the moment the downstream step needs it (hydration):

// Convert a file URL into a Zapier file object
const filePointer = z.dehydrateFile(inputData.file_url);

output = {
  file: filePointer
};

Map the file output field to the attachment or file field in the downstream step. That's the complete pattern for a publicly accessible URL.

Hydrating Files from Authenticated URLs

APIs frequently return download URLs that require authentication. Pass the required headers in the options parameter:

// Bearer token authentication
const filePointer = z.dehydrateFile(inputData.download_url, {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${inputData.api_token}`
  }
});

output = {
  file: filePointer,
  filename: inputData.filename || 'download'
};
// API key in header
const filePointer = z.dehydrateFile(inputData.download_url, {
  method: 'GET',
  headers: {
    'X-Api-Key': inputData.api_key
  }
});

output = { file: filePointer };

Building the Download URL Dynamically

Some APIs require you to construct the download URL from a record ID or other parameters before dehydrating:

// Build an authenticated download URL from a record ID
const recordId = encodeURIComponent(inputData.record_id);
const downloadUrl = `https://api.example.com/files/${recordId}/download`;

const filePointer = z.dehydrateFile(downloadUrl, {
  headers: {
    'Authorization': `Bearer ${inputData.api_token}`,
    'Accept': 'application/pdf'
  }
});

// Build a descriptive filename from Zap data
const filename = `${inputData.client_name}-Invoice-${inputData.invoice_number}.pdf`
  .replace(/[^a-zA-Z0-9.\-_]/g, '-'); // sanitize for safe filenames

output = {
  file: filePointer,
  filename: filename
};

Passing the File to Downstream Steps

Once the Code step outputs a dehydrated file pointer, map it to the file attachment field in the next step. Common destinations:

  • Gmail — Send Email: Map to the "Attachments" field. Gmail's Zapier integration accepts dehydrated file references.
  • Google Drive — Upload File: Map to the "File" field. Set the filename in the "File Name" field separately from the Code step's filename output.
  • Dropbox — Upload File: Map to the "File" field.
  • Slack — Send File: Map to the "File" field.
  • Airtable — Update Record (attachment field): For Airtable attachments with custom filenames, see setting Airtable attachment filenames via API PATCH — the native Airtable Zapier action may not use the dehydrated filename.

z.dehydrateFile() vs. z.stashFile()

Zapier Code steps also have z.stashFile() for stashing file contents you've already fetched into Zapier's file store. Use cases:

  • z.dehydrateFile(url): You have a URL. Zapier fetches the file later when needed. Best when the URL is stable and accessible at hydration time.
  • z.stashFile(stream): You've already fetched the file as a stream in your Code step (e.g., from a fetch response) and want to stash it in Zapier's store immediately. Returns a URL that can be dehydrated. Best for expiring URLs or when you need to transform the file contents before stashing.

For most use cases — converting an API's download URL into a file object — z.dehydrateFile() is simpler and sufficient.

Not sure whether a file needs conversion before later steps can read it? See binary vs text-based files.

Troubleshooting File Hydration Issues

If a downstream step fails to attach the file:

  • Verify the URL is accessible from Zapier's servers at the time the downstream step runs (not just at Code step execution time). For expiring signed URLs, the URL may have expired by hydration time — use z.stashFile() to fetch and stash immediately instead.
  • Check that the URL returns the file directly (200 with file content-type), not a redirect to a login page or another URL.
  • Confirm the downstream step's app integration actually accepts file objects — some Zapier app actions only accept URLs or have specific requirements documented in their field descriptions.
z.dehydrateFile() is a one-liner that solves the most common file-handling gap in Zapier: when you have a download URL but need a file object. The dehydration pattern is efficient — Zapier stores a pointer, not the file itself, and only fetches the actual bytes when a step needs to use the file. For authenticated download URLs from APIs, passing the Authorization header in the options is all that's needed.

For fetching and inspecting file contents inside the Code step itself, see getting file contents with a GET request in Zapier. For HTTP GET request patterns in Code steps, see HTTP GET requests in a Zapier Code step. For help with a file routing or processing workflow, talk to Automation Ace.

ZapierCode StepsFile Automation

Disclaimer: This article may include links to apps, products, or services. Some links may be affiliate links, which means Automation Ace may earn a commission at no extra cost to you.

Build Better Systems

Ready to automate with confidence?

Share your tools, process, and goals. Automation Ace can design the workflow, integration, AI assist, or code bridge that fits your business.

Start a Project →