Home > Mobile >  Retrieve Google Form edit URL given the view URL
Retrieve Google Form edit URL given the view URL

Time:10-08

I would like to get response data from a Google Form using the Apps Script API. As per the documentation, the following command must be used to retrieve a form from a specified URL.

// Open a form by URL.
var form = FormApp.openByUrl(
    'https://docs.google.com/forms/d/1234567890abcdefghijklmnopqrstuvwxyz_a1b2c3/edit'
    );

The only problem is I am not given the edit URL, only the public viewing URL. It looks like https://docs.google.com/form/d/abcdefghijklmnopqrstuvwxyz_slightly_different_id/viewform.

I am the owner of the form and can easily retrieve the edit URL by navigating to the public URL and clicking the edit button, but want an automated solution that can ideally be done through the Apps Script API.

So, how do I retrieve the edit URL of a Google Form I own using the Apps Script API when given the view-only URL?

CodePudding user response:

If your final goal is to obtain the edit URLs of your Forms without accessing the browser interface, there is a workaround that you can use on Drive. You only have to develop an approach in DriveApp that opens the folder where you save the Forms and then interacts with the results grabbing all the URLs. See below for an example returning an array of all the edit URLs.

function getFormEditURLs() {
  var forms = DriveApp.getFolderById('{ YOUR FOLDER HERE }')
    .getFilesByType(MimeType.GOOGLE_FORMS);
  var formsEditURLs = [];
  while (forms.hasNext()) {
    var form = forms.next();
    formsEditURLs.push(FormApp.openByUrl(form.getUrl()).getEditUrl());
  }
  return formsEditURLs;
}
  • Related