Has anyone ever used GAS to upload binary files to PipeDrive using the UrlFetchApp method?. specifically I want to download an Mp3 file from a url (which I have done using app script) and upload the binary format of the file to PipeDrive using PipeDrive API. If any one has any ideas please help! thanks.
Here’s one I created a while ago to upload a PDF to Pipedrive. Don’t remember exactly how it works but maybe it will help?
function addPmpToPd(useData, client) {
// Submit PDF to Pipedrive as well
client.pdf = { 'blob': client.file.getBlob() };
var boundary = "uploadpmp";
var requestBody = Utilities.newBlob("--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"file\"; filename=\"" + client.fileName + "\"\r\n" +
"Content-Type: " + client.pdf.blob.getContentType()+"\r\n\r\n").getBytes().concat(client.pdf.blob.getBytes());
requestBody = requestBody.concat(Utilities.newBlob("\r\n--" + boundary + "\r\n" +
"Content-Disposition: name=\"person_id\"\r\n\r\n" + client.pd.person.id + "\r\n--" + boundary + "\r\n" +
"Content-Disposition: name=\"deal_id\"\r\n\r\n" + client.pd.deal.id + "\r\n--" + boundary +
"--").getBytes());
var add = {
"query": ("https://domain.pipedrive.com/v1/files?api_token=" + useData.api),
"options": {
'method' : 'post',
'accept': 'application/json',
'contentType': 'multipart/form-data; boundary='+boundary,
'payload': requestBody
}
};
var theResponse = JSON.parse(UrlFetchApp.fetch(add.query, add.options).getContentText());
} /* end addPmpToPd() */