I needed to generate checksums for files in my Zapier automation but couldn’t find built-in crypto functions. Here’s my JavaScript solution that downloads a file from a URL and creates a SHA256 hash.
My approach:
- Download file from public URL
- Generate SHA256 checksum
- Output the hash value
const cryptoLib = require('crypto');
return fetch(inputData.documentUrl)
.then((response) => {
console.log('Response OK:', response.ok);
console.log('Status Code:', response.status);
return response.buffer();
})
.then((fileBuffer) => {
const hasher = cryptoLib.createHash('sha256');
hasher.update(fileBuffer);
callback(null, {"checksum": hasher.digest('hex')});
})
.catch(callback);
The process works by fetching the file content, converting it to a buffer, then using Node’s crypto module to generate the hash.
Important considerations:
- Zapier JavaScript actions only accept string inputs, so files must be accessible via public URLs
- For sensitive files, consider removing them after processing
- Special characters in URLs (like ‘€’) can cause 403 errors with some storage providers
This has been helpful for maintaining data integrity in automated accounting workflows.
I’ve hit similar performance issues with this approach. For larger files, the synchronous buffer conversion times out in Zapier’s environment. Streaming the response and updating the hash incrementally works way better - just replace response.buffer() with response.body.pipe() to a hash stream. This prevents memory issues and timeouts. Also heads up: some CDNs and storage providers return different content-encoding headers that mess with hash calculations. Setting the encoding explicitly in your fetch request keeps results consistent across different file sources.
nice solution! quick heads up - fetch doesn’t handle redirects well by default, so adding redirect: 'follow' to your options fixes most issues. also watch out for urls with query parameters. if you don’t encode them properly, you’ll get weird hash mismatches when the server interprets them differently.
Heads up - Zapier’s JavaScript environment has request timeout limits that’ll break this with files over a few MB. Hit this issue processing PDF invoices and switched to a webhook approach instead. I trigger an external service that handles the download and hash generation, then posts back to Zapier with the result. External service gives you way more control over timeouts and error handling. Also, some file hosting services need specific user-agent headers or they’ll block automated requests. Adding a proper user-agent string to your fetch options usually fixes those 403 errors you mentioned.