I'm trying to get data from a csv file in attachment in my my Gmail, parse it and import it with Google Script in Google Sheets.
Problem is when I get content type of my attachment I have this message "application/octet-stream" and not CSV so I think algorithm doesn't keep on in if condition.
Do you have suggestion why I don't get right file type ?
Big thanks !
Here's the code :
function importCSVFromGmail() {
var threads = GmailApp.search("Money Transfer Tracking - Tickets");
var message = threads[0].getMessages()[0];
var attachment = message.getAttachments()[0];
console.log(attachment.getContentType())
// Is the attachment a CSV file
if (attachment.getContentType() === "text/csv") {
var sheet = SpreadsheetApp.getActiveSheet();
var csvData = Utilities.parseCsv(attachment.getDataAsString(), ";");
// Remember to clear the content of the sheet before importing new data
sheet.clearContents().clearFormats();
sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
}
}