Skip to main content
Front Developer
Fronteer
December 6, 2022
Solved

Create draft SDK help - draft doesn't include attachments

  • December 6, 2022
  • 5 replies
  • 326 views

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'
}
});

 

Best answer by Javier - Developer Relations

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.

5 replies

Javier - Developer Relations
Community Manager
December 6, 2022

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

Javier - Front Developer Relations
Front Developer
Fronteer
December 6, 2022

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?

Javier - Developer Relations
Community Manager
December 6, 2022

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?

Javier - Front Developer Relations
Front Developer
Fronteer
December 6, 2022

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

Javier - Developer Relations
Community Manager
December 6, 2022

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.

Javier - Front Developer Relations