How to retrieve and store file data from external API using Zapier integration

I’m working on building a custom Zapier integration that needs to download binary file data from my external API endpoint. The goal is to grab these files and make them available for use in other Zapier workflows.

I’ve been going through the documentation but I can’t seem to get my implementation working correctly. The file retrieval process isn’t behaving as expected and I’m not sure what I’m missing.

Here’s my current approach:

const requestConfig = {
  url: `https://myapi.example.com/download`,
  method: 'GET',
  raw: true,
  headers: {
    'Authorization': `Bearer ${bundle.authData.token}`
  }
}

const downloadFileHandler = (z, bundle) => {
  // make authenticated request to fetch file
  const fileRequest = z.request(bundle.inputData.requestConfig);
  // convert to stashed file URL
  return z.stashFile(fileRequest);
};

const finalResult = z.dehydrateFile(downloadFileHandler, {
  requestConfig: requestConfig
});
return finalResult;

Any suggestions on what might be going wrong or alternative approaches I should try?

You’ve got the right components but there’s a structural issue with your request flow. The main problem is you’re mixing synchronous and asynchronous patterns incorrectly.

I hit the same wall when building my first file integration. What fixed it for me was simplifying the approach and chaining the promises properly:

const performDownload = (z, bundle) => {
  return z.request({
    url: `https://myapi.example.com/download`,
    method: 'GET',
    raw: true,
    headers: {
      'Authorization': `Bearer ${bundle.authData.token}`
    }
  }).then(response => {
    return z.stashFile(response);
  });
};

The key difference is chaining the request and stash operations with .then(). Your current code tries passing the promise directly to z.stashFile() before it resolves, which makes the integration fail silently. Also double-check your API endpoint returns the correct Content-Type and Content-Disposition headers for binary files.

First, make sure your API endpoint actually supports GET for downloads. Some APIs need POST with specific body params instead. Also try using both raw: true AND responseType: 'stream' at the same time - that fixed it for me when just raw wasn’t cutting it.

Had the same issue building my integration last year. The problem is how you’re passing the request config to z.stashFile(). You’re creating the requestConfig object then wrapping it in bundle.inputData, which adds an extra layer that breaks things.

Just pass the request directly to z.stashFile() without the dehydration wrapper:

const fileRequest = z.request({
  url: `https://myapi.example.com/download`,
  method: 'GET',
  raw: true,
  headers: {
    'Authorization': `Bearer ${bundle.authData.token}`
  }
});

return z.stashFile(fileRequest);

z.dehydrateFile() is for larger files or when you need to defer downloads, but the direct approach works fine for most cases. Also double-check your API endpoint is actually returning file content with proper headers - that tripped me up at first.