Can you submit a Restful request to a google forms api?

10.3k Views Asked by At

I want to use google forms to collect questionnaire responses but with a much more custom UI for doing so. Is there a way to send in responses from my custom application to my google forms api?

5

There are 5 best solutions below

0
On BEST ANSWER

You can use the endpoint to fill the google form directly. Steps -:

  1. Create a google sheet.
  2. Click on the Tool menu to create a google form.
  3. Then create some google forms fields.
  4. Now in the right top corner click on the 3 dots and select the Pre-fields link form.
  5. Fill the info and click on the Get link and copy the link
  6. Now you have a URL with the endpoints like this Endpoints are

entry.1651815625.

entry.952362665

Google Sheet Link for Form -: "https://docs.google.com/forms/d/e/1FAIpQLSfxoz5dqXC-_LoGJWZCPasww6woHcOl0s48PYcCj-72uUJoBQ/viewform?usp=pp_url&entry.1651815625=Radha&entry.952362665=Krishna"

To Convert this link to this way

"https://docs.google.com/forms/d/e/1FAIpQLSfssz5dqXC-_LoGJWZCP93ww6woHcOl0s48PYcCj-72uUJoBQ/formResponse?&submit=Submit?usp=pp_url&entry.1651815625=Radha&entry.952362665=Krishna"

Instead of "viewform" you have to write "formResponse?&submit=Submit"

Now you can pass your own value and hit this URL to submit your google form directly.

For more info, you can watch this video from The Coding Bus https://youtu.be/PVM7h5QCnnM

2
On

If you want to update the form's layout, it is possible to update it from your application using the Google Forms API. However, the Google Forms API currently does not support sending responses to your form, as shown here

3
On

At this time the Google Forms REST API doesn't support creating form responses as the Form.responses resource only includes two methods: get and list. Ref. https://developers.google.com/forms/api/reference/rest/v1/forms.responses?hl=en

You might use the Forms Service from Google Apps Script to create Google Forms Responses programmatically. To call this service from your app you might create a web-app in order have a HTTP GET / POST request end-point or use the Google Apps Script REST API.

Another option might be to use a "hack" to emulate the Google Forms POST request. See Auto-Fill or automate a Google Form

Related

0
On

"Is there a way to send in responses from my custom application to my google forms api?"

Assuming that you mean user supplied questionnaire responses, then the short answer to your question is No!

Currently, Google Forms does not accept questionnaire responses via the google forms api. The google forms api is intended only for managing your google forms documents and not for accepting user responses.

However, considering that the user responses submitted from a google form are ultimately saved into a google sheet, you may be able to send in user questionnaire responses from your custom application using the google sheets api.

Keep in mind though that it can get tricky trying to make updates programmatically to data in google sheets. If your use case will not include making updates then you should be fine otherwise you're probably better off just using your favourite db storage system.

1
On

I have codified the details mentioned by above answers.

Here is what I did in R

gf_url_parse<- function(gfurl){
  l_entries <- list()
  et <- strsplit(gfurl, "&entry.")[[1]]
  if(length(et)>1){
    entries <- et[-1]
    vals <- unlist(lapply(strsplit(entries, "="), `[[`,2))
    entries <- unlist(lapply(strsplit(entries, "="), `[[`,1))
    entries_d <- data.frame(entries, vals, stringsAsFactors = FALSE)
    l_entries <-lapply(split(entries_d, entries_d$entries), function(x) x$vals)
    l_entries <- l_entries[unique(entries_d$entries)]
  }
  l_entries
}

gf_url_make <- function(entries, gfurl_sample){
  base_url <- strsplit(gfurl_sample, "&entry.")[[1]][1]
  var_part <- paste0(
    "&entry.",
    unlist(
      lapply(
        names(entries), 
        function(nn){
          paste0(nn,"=",entries[[nn]])
        }
      )
    ), 
    collapse = "")
  paste0(base_url, var_part)
}

gf_url_submit <- function(gfurl_compiled){
  gfurl_compiled_prep <- gsub(
    pattern = "/viewform?",replacement = "/formResponse?&submit=Submit?", 
    x = gfurl_compiled)
  tryCatch(
    suppressWarnings(RCurl::postForm(gfurl_compiled_prep)), 
    error = function(e) NULL
  )
  invisible(0)
}