Solved

Create draft SDK help - draft doesn't include attachments

  • 6 December 2022
  • 5 replies
  • 58 views

Badge +2

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: ['acme@example.com'],
subject: "Your invoice for the order: ",
attachments: ['./X.pdf', 'path/X.pdf'],
content: {
body: 'Invoice attached.',
type: 'text'
}
});

 

icon

Best answer by Javier - Developer Relations 6 December 2022, 23:54

View original

5 replies

Userlevel 5
Badge +8

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

Badge +2

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?

Userlevel 5
Badge +8

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?

Badge +2

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

Userlevel 5
Badge +8

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(["foo"], "foo.txt", {
type: "text/plain",
});

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

 

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

Reply