0

Hopefully the question is self-explantory - I have looked in quite a few places and cannot find an answer to my question:

Question: With a pre-filled URL for a Google Form, is it possible to take that as an input in a Google Script code and submit the form response?

Thank you!

TheMaster
  • 45,448
  • 6
  • 62
  • 85
JohnTyler
  • 1
  • 1
  • 1
    About `submit a Google Form in Google Scripts`, in this case, I thought that this thread might be useful. https://stackoverflow.com/q/69293786 – Tanaike Oct 30 '21 at 04:59
  • 1
    @Tanaike So just a `post` to the Google forms view url submits the form – TheMaster Oct 30 '21 at 09:26
  • 1
    @TheMaster Yes. The answer can be requested with the POST method as the query parameter. As a specification, when the single answers are used, those answers can be requested by including the request body. When the multiple answers are used, it seems that this is required to request as the query parameter. For example, when the size of answers is large, those might not be able to be requested with the query parameter. At this time, I thought that when the request body is used, it can be resolved. – Tanaike Oct 30 '21 at 11:52
  • @Tanaike Just to clarify, what's the endpoint url? Google forms view url or the forms api? – TheMaster Oct 30 '21 at 12:21
  • 1
    @TheMaster In the current stage, it's the Google Form. Of course, when I got to be able to test Google Forms API, I'm thinking that I want to try this. – Tanaike Oct 30 '21 at 12:23

1 Answers1

1

The answer by @Mogsdad does just the opposite. To do the reverse, You'll just have to "parse" the template form prefilled url to the corresponding item number.

var template = "https://docs.google.com/forms/d/--form-id--/viewform?entry.726721210=##Name##&entry.787184751=##Birthday##&entry.1381372492&entry.960923899";

Create a formResponse. Then, if entry.726721210 corresponds to the first item, you'll createResponse() for that item. Similarly createResponses for all items and finally call formResponse.submit().

TheMaster
  • 45,448
  • 6
  • 62
  • 85