I've been consuming StackOverflow info for years now and have never posted, but I've finally found something that stumps me, and doesn't seem to have a direct response anywhere. I work in Google Apps Script, and have successfully integrated scripts with the SendGrid V3 Web API to send emails, including emails with attachments. But for some reason I can't get it to work with a PDF pulled from Google Drive. Here is how I'm creating the attachment:
var filePath = "https://drive.google.com/file/d/19rzCtnOMWw0ZZM4FViMWVZWkRRnsWx3L/view?usp=sharing";
var response = UrlFetchApp.fetch(filePath);
var attachment = Utilities.base64Encode(response.getContent());
... and here is the object I'm passing to the v3/mail/send endpoint:
"attachments": [{"content": attachment, "type": "application/pdf", "filename": "testPDF.pdf"}]
When I do this, I receive an email with a PDF attachment, and the attachment is the same size as the PDF file in Google Drive. But when I try to open it, I get an error telling me I can't preview the file, and telling me to try downloading it instead. When I download and open, I get an "Error: Failed to load PDF document" message. Clearly I'm somehow creating an attachment that is not a proper PDF document. Is there anything in the above that someone can spot that I'm doing wrong?
I'm self-taught and a bit of a hack, so I apologize in advance if I'm missing something obvious, or if I've excluded critical information.