Skip to main content

This post has been edited by a moderator to remove personal information. Please remember that this is a public forum and to remove any sensitive information prior to posting.

Hi there,

I am not NodeJS expert at all and I met troubles to manage attachment.

 

Our service “Postee” (We secure and track electronic communication) needs to allow a user to send a PDF.

As simply for a user, it works in front as en email. we need a recipient, an object, a message (not mandatory) and an attach file (only PDF and also not mandatory). A user should at least write directly a message or join files (PDF) or both. 

By the way, it should work as the action of the gmail zap for example but in my case I have some troubles to manage the code :(

To test my action I have try to automate a sending from our service if a payment fail in stripe. 

The context : Send to the client who have a payment failure a Message from our service Postee to him with the invoice with attach. 

here is the code : 

const http = require('https');

 

const makeDownloadStream = (z, bundle) => {

  var imageRequest = {

    url: bundle.inputData.Attachment,

    method: 'GET',

    raw: true,

  };

 

  const promise = z.request(imageRequest);

  return promise.then(async (response) => {

    var buffer = await response.buffer();

    return {

      'content-type': response.headers.get('content-type'),

      content: buffer,

      filename: response.headers

        .get('content-disposition')

        .replace('attachment; filename="', '')

        .replace('"', ''),

    };

  });

};

 

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

  const content = await makeDownloadStream(z, bundle);

 

  const FormData = z.require('form-data');

  const formData = new FormData();

  formData.append('SelectedReceivers', bundle.inputData.SelectedReceivers);

  formData.append('Object', bundle.inputData.Object);

  formData.append('Message', bundle.inputData.Message);

  formData.append('SelectedGroups', bundle.inputData.SelectedGroups);

 

  formData.append(

    `Attachment`,

    Buffer.from(content.content.toString('binary'), 'binary'),

    {

      filename: content.filename,

    }

  );

 

  return z

    .request({

      url: 'https://api.postee.io/api/Letters/SendPosteeCourrier',

      method: 'POST',

      body: formData,

      headers: {

        mimeType: 'multipart/form-data',

        Accept: 'application/json',

        Authorization: `Bearer ${bundle.authData.access_token}`,

      },

    })

    .then((response) => {

      response.throwForStatus();

      const results = response.json;

 

      // You can do any parsing you need for results here before returning them

 

      return results;

    });

};

 

module.exports = {

  key: 'Send_Postee_Courrier',

  noun: 'Postee Courrier',

  display: {

    label: 'Postee Courrier',

    description: 'Send Postee Courrier',

    hidden: false,

    important: true,

  },

  operation: {

    inputFields:

      {

        key: 'SelectedRecipents',

        label: 'Recipients',

        type: 'integer',

        default: '0',

        required: false,

        list: false,

        altersDynamicFields: false,

      },

      {

        key: 'SelectedGroups',

        label: 'Contacts Group',

        type: 'integer',

        default: '0',

        required: false,

        list: false,

        altersDynamicFields: false,

      },

      {

        key: 'Object',

        label: 'Object',

        type: 'string',

        required: true,

        list: false,

        altersDynamicFields: false,

      },

      {

        key: 'Message',

        label: 'Message',

        type: 'string',

        required: true,

        list: false,

        altersDynamicFields: false,

      },

      {

        key: 'Attachment',

        required: false,

        type: 'file',

        label: 'Attachment'

      }

    ],

    perform: perform,

  },

};

Here is the the setting of the zap 

Here is the error : 

 

As I am clearly not an expert, I can not understand what’s wrong :(

 

Please help

Hi @RomainRCD!

To make sure that we can help you to find folks to look at your issue, could you let me know if you are creating your own Zapier integration for Postee or if you’re trying to work with Postee using a Code step in your Zap. 

Thanks!


Hey, Hi @Danvers 

We are developing our own integration.

 

We are developing triggers and actions and we hope to be able to publish it to become “partnered” ASAP ;)