Solved

Sending Calendar Invites Thru API

  • 13 January 2023
  • 1 reply
  • 13 views

Badge +2

We’re hoping to send calendar invites through Front messages.

 

Historically we’ve included the calendar invite as inline to the message using the multipart/alternative property where the invite renders as part of the message, but not sure this is available through the Front API.

icon

Best answer by Support Engineering 13 January 2023, 16:27

View original

1 reply

Badge +5

You can send the payload to the Front API with a multipart/form-data content-type to include attachments.

 

In this example, I'm including a .ics attachment, along with the HTML and plain-text parts of an email.

 

const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');

async function run() {
const url = 'https://api2.frontapp.com/channels/CHANNEL_ID/messages';

const form = new FormData();

form.append('author_id', 'alt:email:jason+demo3@example.com');
form.append('to[]', 'jason@example.com');
form.append('to[]', 'erik@example.com');
form.append('subject', 'Message Subject');
form.append('body', '<p>Message Body</p>');
form.append('text', 'Message Body');
form.append('attachments[]', fs.createReadStream('/Users/jason/Downloads/invite.ics'));


axios.post(url, form, {
headers: {
Authorization: 'Bearer API_TOKEN'
}
})
}

run()

So this is JS code, using the axios and form-data NPM packages to send a request.

 

We append the required "form fields" to the message, and for fields that support array types (like "to"), we can add multiple elements.

 

For the attachment, you will need to generate the ICS file (for my example, I just downloaded an example I already had.)

 

The screenshot shows the received message in Front. It also shows the typical "accept/decline" buttons on the message when viewing it in Gmail. 

 

This example can be run either directly in a terminal by starting a node session, or pasting the content into a .js file and running node <filename>.js (the CHANNEL_ID, API_TOKEN and other variable values should also be updated.)

 

I hope that's helpful

 

--Jason

Reply