1
votes

I'm using a custom created google apps script to send out some emails. I have a PDF in my google drive that I am trying to attach to an email but it is not working. I keep on getting the error "Document is missing (perhaps it was deleted?)"

Here is my full code...

    function sendDetails(e) {
var itemURL = 'https://docs.google.com/file/d/0Bw7JWLKeRBKASUFldGM1RTRIaFE/edit';
var docName = DocumentApp.openByUrl(itemURL).getName();
}

Note that the above PDF is a publicly accessible PDF file that anyone can get to. I know it exists but it's not allowing me to access it. All that I am trying to do is take the file and attach it to an email. There is obviously more to my code than the about but I trimmed down just to that to try to narrow the error and no such luck. Any help would be greatly appreciated.

1
You shouldn't have trimmed that much... I'm afraid no one will be able to help with that few information. The message you get just means that the URL is not valid or that you don't have authorization to open it... how did you get the URL? Who is the owner?Serge insas

1 Answers

5
votes

DocumentApp deals with Google Documents - Google's WordPad-like editor. Since the file in question is a PDF, it's not available to DocumentApp.

Instead, you should be using DriveApp. Additionally, since there is no DriveApp method to open a file by URL, you need to use DriveApp.getFileById(). (The ID is "0Bw7JWLKeRBKASUFldGM1RTRIaFE" in your example.)