I built an application that pulls information from a fusion table and generates a Google document based on a predefined template. After creating the doc, it converts to PDF format and shows a download link. Everything works perfectly when I test it myself, but other users in my company get a “404 Not Found” message when they try to access the link. I think this happens because the document permissions are set to private by default. Is there a programmatic method to automatically grant viewing access to all members of my organization when the document gets created? Or maybe there’s a different approach I should consider for sharing these generated files?
Just hit the Google Drive API’s permissions endpoint right after you create the document. Call drive.permissions.create with your company domain and set the role to ‘reader’ - boom, everyone in your org gets access without needing individual emails. I ran into the exact same thing with automated reports last year and this fixed it completely. Your service account needs domain-wide delegation and the https://www.googleapis.com/auth/drive scope. Works instantly, so people can grab the PDF download right away.
I ran into this exact same thing when building document automation for our finance team. Best fix I found was setting permissions right when you create the document, not as a separate step after. When you call the Drive API to create the document, just include the permissions parameter directly in the create request. Set type to ‘domain’ and specify your org’s domain. This kills the race condition where people try hitting the link before permissions kick in. Also make sure your service account has the right org permissions in your Google Workspace admin console - if that’s not set up, domain-wide sharing won’t work no matter what you do with the API.
yeah, there’s another way if u don’t want to deal with the permissions api every time. just create the doc in a shared folder that’s already set up with org-wide access. way simpler than calling apis after each doc creation, and it won’t break when google changes their apis around.
This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.