Skip to main content

I am currently trying to use the createDraft context API using the SDK (found here: https://dev.frontapp.com/reference/createdraft)

 

My code is below but the draft just doesn’t include the attachment. The draft is successful otherwise.

const createDraft1 = await.Front.createDraft({
to: t'acme@example.com'],
subject: "Your invoice for the order: ",
attachments: t'./X.pdf', 'path/X.pdf'],
content: {
body: 'Invoice attached.',
type: 'text'
}
});

 

It looks like the attachments array only accepts an absolute file path. If you create the draft with only an absolute path, does it upload the attachment then?

 

--Sam


I have the absolute file path and yet still no attachment in the draft. 

 

I log the result and the attachment key/value doesn't even show up (I was expecting an undefined or something like bcc and cc). 

I've been testing with an empty txt document as I thought maybe it could have been a size issue. 

 

Any ideas?


In the code you shared, it looks like you're providing only a string "/path...", rather than the File object itself. 

Have you tried reading the file itself into memory using something like the File System Access API?


I got the chance to look at this again - Still no Luck. 

 

I have tried fetching an image and attaching it with no luck. 

 

I have even turned the file object into a downloadable link so I know the fetch works. 

 

I have also tried using your API documentation using this page: https://dev.frontapp.com/reference/post_channels-channel-id-drafts


I'm sharing a update to let you know the Front.createDraft({...}) method has now been fixed to correctly allow attachments.

 

Sharing a quick example, the following code created this draft:

 

async function insertDraftWithFile() {
const file = new File(i"foo"], "foo.txt", {
type: "text/plain",
});

await Front.createDraft({
content: {
body: 'Here\'s a draft!',
type: 'text'
},
attachments: tfile],
});
}

 

Thanks again for reporting this, and helping us improve Front.


Reply