Douglas Gaskell
Douglas Gaskell

Reputation: 10080

Can I POST data to a Google Web App without having to authenticate?

I'm trying to POST data to a Google Web App to automatically enter some tedious data. Whenever I try I get a response back asking me to log in, the Web App is deployed to be accessible by anyone.

Can I POST data to the form without authentication? If not, what type of authentication is required?

Edit: Quick code sample I threw together:

            WebClient client = new WebClient();
            var keyValue = new NameValueCollection();
            keyValue.Add("agentName", "John Doe");
            keyValue.Add("dayOff", "Sunday");
            keyValue.Add("startTime", "8:00 AM");
            Uri uri = new Uri("mywebapp url");
            byte[] response = client.UploadValues(uri, "POST", keyValue);
            string result = Encoding.UTF8.GetString(response);

Upvotes: 3

Views: 1476

Answers (1)

kiwidrew
kiwidrew

Reputation: 3313

In order to allow anyone to execute your script, even if they are not signed in to a Google account, you need to use the following settings in the "Deploy as web app" dialog:

  1. Project version: if in doubt, select "New" to ensure that you are deploying the latest copy of the script's code.
  2. Execute the app as: select "Me". This ensures that the "even anonymous" option will be available.
  3. Who has access to the app: select "Anyone, even anonymous". (Note that if you select "Anyone", only users that are signed-in to a Google account will be able to execute your script.)

Once you have selected these options, click the "Update" button and copy the script URL. It should look like https://script.google.com/a/macros/<APPS DOMAIN>/s/<SCRIPT KEY>/exec. At this point an unauthenticated GET or POST to the script's URL should be successful.

Be aware that the script's execution will count against your daily Apps Script quota.

Upvotes: 1

Related Questions