Skip to main content

We are calling “create a Note” API of fresdesk from Salesforce but not able to send attachments in the correct format. Can anyone please help with an example of how to send attachments with the request ?

 

Our code:

LWC

onFileUpload(event) {

        console.log('event.target :: ', event.target);

        console.log('event.target.files, ', event.target.files);

        const file = event.target.files[0];

        console.log('file:: , ', file);

     

        var reader = new FileReader()

        reader.onload = () => {

            console.log('reader.result :: ', reader.result);

            // var base64 = reader.result.split(',')[1]

            // this.fileData = {

            //     'filename': file.name,

            //     'base64': base64

            // }

 

            this.fileData.name = file.name;

            this.fileData.base64 = reader.result.split(',')[1];

            this.fileData.file_size = file.size;

            this.fileData.content_type = file.type;

        }

        reader.readAsDataURL(file);

 

        console.log('filedata', this.fileData);

        console.log('filedata', [this.fileData]);

 

        this.newNoteFormData.attachments = [this.fileData];

    }

 

Sample req body:

 

{

“body”:”Sample body”,

private:true,

attachments[] : [this.fileData]

}

 

we are sending FileData as a string in the request body.

To correctly send attachments with the "Create a Note" API call from Salesforce to Freshdesk, you need to construct a multipart/form-data request, including the file data as binary rather than a string within the request body.