13

I keep getting this error message when I try to click "Test web app for your latest code." in the Publish dialog box.

But I haven't defined any function called doGet().

My code is only:

function unreadCount() {
  var unreadNum = "Messages unread in inbox: " + GmailApp.getInboxUnreadCount();
  return unreadNum
}
David
  • 208,112
  • 36
  • 198
  • 279
Anirudh Ajith
  • 887
  • 1
  • 5
  • 15

3 Answers3

15

Every webapp in Google Apps Script must have a main function called doGet() which is the entry point of the app, the function that your app will start with when you type the webapp url.

This is true for every application deployed as a standalone app and called by its url - with a user interface or not.

If you read the documentation you'll see that all the standalone apps examples for HTMLService or UiApp have a doGet function.

Only container embedded ui scripts or scripts that run on triggers are not concerned by this rule.

Knowing that, the error message you get is probably more meaningful isn't it ?

Serge insas
  • 45,904
  • 7
  • 105
  • 131
  • 1
    I got the error after deploying a Google Docs Add-on. I followed the Quickstart at https://developers.google.com/apps-script/quickstart/docs which has no doGet(). My add-on works great for me, so I deployed it as a Web App, and got the error above after seeing a recommendation to `Test web app for your latest code.` on the **Deploy as web app** screen. – Fuhrmanator Apr 04 '14 at 13:26
  • deploying addon and deploying webapps are two completely different things... please re-read the doc about add-ons . These must be approved by Google and are still in development mode... al this is pretty well explained – Serge insas Apr 04 '14 at 13:32
  • 2
    Thanks - I see now. The Script Editor doesn't seem to know the difference, and let me "Publish -> Deploy as web app" my add-on (there's no question or verification of which development I was doing). The [add-on quickstart mentions "Publish"](https://developers.google.com/apps-script/quickstart/docs#publish) but as you say, it's not the same Publish as in the Script Editor. Google will likely have to clear this up, but as you say it's very new. – Fuhrmanator Apr 04 '14 at 15:59
  • similar to Data2000 i am having this issue, however you answer shows no ways of fixing it. I know it is not your fault that google provided bad tutorial but still share your wisdom how to fix it. Tx – Boris Gafurov Oct 31 '16 at 16:51
  • just use a function called "doGet" from which you start your program execution, I don't understand what other solution could be more obvious and simple. What issur do you actualla meet ? – Serge insas Oct 31 '16 at 21:10
  • @Fuhrmanator 8 years later, and no, Google has not 'cleaned it up'... as they should have done by now. But naah. Who cares about newbie developers, either in 2014 or 2022? – Gwyneth Llewelyn Aug 07 '22 at 15:41
6

As Serge insas said, you must first implement the function doGet(e) as described in Google's documentation.

However, after you implement it, make sure to save a new version of your project (File > Manage versions... and then save the new version) and then deploy the new version of your web app. Else you will continue to get the "doGet not implemented" error from Google. This is because it is still using the old version of your application, before you implemented doGet.

Kayce Basques
  • 23,849
  • 11
  • 86
  • 120
  • 2
    You don't need to goto manage versions. You can just do Publish>Deploy as Web App> and select "new" in the project version dropbox. Seriously, Google should get rid of this requirement or atleast warn developers clearly, since its not intuitive. – Sujay Phadke Jan 03 '16 at 23:04
  • 1
    Nope. Not intuitive at all. It's 2022 and it's still the same mess. – Gwyneth Llewelyn Aug 07 '22 at 15:42
  • @GwynethLlewelyn indeed, just spent an hour trying to figure out what was wrong with my app script until I finally found this – Nathan Tew Dec 01 '22 at 09:48
2

I received this error because I had defined a doPost() function in my Google Script but my form was submitting a GET request rather than a POST request.

The solution to this problem was to submit a POST request from the form:

<form action='google-script-here' method='post'>

duhaime
  • 25,611
  • 17
  • 169
  • 224