Skip to main content
Best answer

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

  • September 28, 2020
  • 3 replies
  • 297 views

Follow Zapier hydration sample code (https://github.com/codebycaleb/zapier-hydration-example/ ) 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 CraigNet3Best answer by CraigNet3

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 = "https://quickbooksApI_Endpoint.com";
formData.append('file', request(file), {filename: filename});
return z.request({
    url: url,
    method: 'POST',
    body: formData
}).then((response) => {
    response.throwForStatus();
    let result = JSON.parse(response.content);                   
    return result;    
});

Let me know if that works.

View original
Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

3 replies

CraigNet3
Forum|alt.badge.img+4
  • Zapier Expert
  • 41 replies
  • Answer
  • October 2, 2020

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 = "https://quickbooksApI_Endpoint.com";
formData.append('file', request(file), {filename: filename});
return z.request({
    url: url,
    method: 'POST',
    body: formData
}).then((response) => {
    response.throwForStatus();
    let result = JSON.parse(response.content);                   
    return result;    
});

Let me know if that works.


  • Author
  • Beginner
  • 1 reply
  • October 7, 2020

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.

 


 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?