Best answer

When uploading a PDF file from Quickbooks new invoice trigger, the file size is 0

  • 28 September 2020
  • 3 replies

Userlevel 1

Follow Zapier hydration sample code ( ) to upload a pdf file from new Invoice trigger for Zapier-Quickbooks integration, but getting file size is 0 -  an empty file with the name "invoice_{number}.pdf

How to handle this case?





Best answer by CraigNet3 3 October 2020, 00:43

View original

3 replies

Userlevel 3
Badge +3

Hi Jonathan, all you have to do is post directly to the QuickBooks Endpoint using FormData, while using request to download the file from a Zapier file field (or URL field). Example:

const request = require('request');
const formData = new FormData();
let file = bundle.inputData.file;
let filename = bundle.inputData.filename;
let url = "";
formData.append('file', request(file), {filename: filename});
return z.request({
url: url,
method: 'POST',
body: formData
}).then((response) => {
let result = JSON.parse(response.content);
return result;

Let me know if that works.

Userlevel 1

Thanks for your help. 

Since I do not upload file to Quickbooks, the “url” points to my service. Using this way, I got the “hydrate” as content - this is incorrect as shown below:

 const uploadFile = async (z, bundle) => {

       const form = new FormData();

       form.append('file', request(bundle.inputData.file));

        const response = await z.request({
       url: url,
       method: 'POST',
       body: form



The way I was using is as follows:


 const { file, filename } = await utils.retrieveFile(z, bundle.inputData.file);

 form.append('file', file, filename);

As for utils.retrieveFile is shown below:

const retrieveFile = async (z, url) => {
  const fileObj = {};
  z.console.log('url: ' + url);

  try {
    const response = await z.request(url, { raw: true });
    z.console.log('response: ' + response);
    const header = response.getHeader('content-disposition');
    fileObj.filename = getFilenameFromContentDisposition(z, header);
    fileObj.file = await response.buffer();  
  } catch (e) {
    throw e;
  z.console.log('file: ' + fileObj.file.toString('hex'));
  return fileObj;


In this case, the file is empty.


Userlevel 1

 Zapier file field (or URL field) But I could not find this type in the input fields type list.




Can you help me how to create file type?