Hi,
We are trying to upload .wav files containing call recordings via the / documents API as shown in the documentation here: Freshsales | Refreshingly new CRM & Deal Management Software, and we are running into some issues. We have tried an xhr and a fetch() approach but we get cors errors returned on both.
We tried to do this with the following code:
function saveCallRecording(contactId, recordingRef, recording, succeshandler, errorHandler) {
let filename = `${recordingRef}.wav`;
let url = `https://${domain}.myfreshworks.com/crm/sales/api/documents`;
let data = new FormData();
data.append("file", new Blob([recording], { type: `multipart/form-data` })); // also tried 'audio/wav'
data.append("file_name", filename);
data.append("is_shared", "true");
data.append("targetable_id", contactId);
data.append("targetable_type", "Contact");
let xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log('Upload recording response: ' + this.responseText);
if (this.status === 200) succeshandler(this.responseText);
else errorHandler(this.responseText);
}
});
xhr.open("POST", url);
xhr.setRequestHeader("Authorization", "Token token=<%= iparam.apiKey %>");
xhr.send(data);
}
We also tried the client request method to upload the file, but on this we get a ‘FormData object could not be cloned.’ response. (In here the body object is the same formdata object as shown above)
function callFreshsaleSuiteApi(body) {
return new Promise(function (resolve, reject) {
let url = `https://${domain}.myfreshworks.com/crm/sales/api/documents`;
let headers = { "Authorization": "Token token=<%= iparam.apiKey %>", "Content-Type": "multipart/form-data" }; // also tried 'audio/wav'
let options = { headers: headers, body: body };
return fssClient.request.post(url, options).then(
function (data) {
resolve(data.response);
},
function (error) {
reject(error);
}
)
});
}
Anyone know how to solve this?