googleapis / google-api-nodejs-client

Google's officially supported Node.js client library for accessing Google APIs. Support for authorization and authentication with OAuth 2.0, API Keys and JWT (Service Tokens) is included.
https://googleapis.dev/nodejs/googleapis/latest/
Apache License 2.0
11.26k stars 1.91k forks source link

Google Forms API requiring email_collection_type enum #3467

Closed irealva closed 2 months ago

irealva commented 2 months ago

Hi, we've been using the Google Forms API for quite some time and about 2 weeks ago it just broke with an error:

{
    "success": false,
    "response": {
        "error": {
            "code": 400,
            "message": "Invalid value at 'requests[0].update_settings.settings.email_collection_type' (type.googleapis.com/google.apps.forms.v1.FormSettings.EmailCollectionType), \"responderInput\"",
            "status": "INVALID_ARGUMENT",
            "details": [
                {
                    "@type": "type.googleapis.com/google.rpc.BadRequest",
                    "fieldViolations": [
                        {
                            "field": "requests[0].update_settings.settings.email_collection_type",
                            "description": "Invalid value at 'requests[0].update_settings.settings.email_collection_type' (type.googleapis.com/google.apps.forms.v1.FormSettings.EmailCollectionType), \"responderInput\""
                        }
                    ]
                }
            ]
        }
    }
}

We've figured out that the value emailCollectionType should be under settings but for the life of me can't figure out what the enum value should be. This seems nowhere to be found in the node API library, in the documentation, or anywhere else. What's going on?

This is what I'm trying:

await fetch(
    `https://forms.googleapis.com/v1/forms/${formId}:batchUpdate`,
    {
      method: "POST",
      headers: headers,
      body: JSON.stringify({
        includeFormInResponse: false,
        requests: [
          {
            updateSettings: {
              settings: {
                quizSettings: {
                  isQuiz: true,
                },
                emailCollectionType: "VERIFIED", // nothing works as a value here
              },
              updateMask: "*",
            },
          },
        ],
      }),
    }
  )
cb-eli commented 2 months ago

Same issue with the .NET Client. I did not find any way to set the EmailCollectionType

cb-eli commented 2 months ago

@irealva I found out that when you change the updateMask value from * to specific fields, it does not return an error.

For example, change the updateMask value to "quizSettings"

irealva commented 2 months ago

Thanks @cb-eli, when I try updateMask: "quizSettings I get another error:

await fetch(
    `https://forms.googleapis.com/v1/forms/${formId}:batchUpdate`,
    {
      method: "POST",
      headers: headers,
      body: JSON.stringify({
        includeFormInResponse: false,
        requests: [
          {
            updateSettings: {
              settings: {
                quizSettings: {
                  isQuiz: true,
                },
              },
              updateMask: "quizSettings",
            },
          },
        ],
      }),
    }
  );
{
    "success": false,
    "response": {
        "error": {
            "code": 400,
            "message": "BatchUpdateFormRequest must contain at least one Request",
            "status": "INVALID_ARGUMENT"
        }
    }
}

Other things I tried

  1. updateMask: "quizSettings" --> "BatchUpdateFormRequest must contain at least one Request"
  2. updateMask: "settings" --> "Invalid field: settings"
  3. No updateMask --> "Update mask required"

In any case this seems like a regression in the API as the updateMask field can clearly take in a "*".

Required. Only values named in this mask are changed. At least one field must be specified. The root info is implied and should not be specified. A single "*" can be used as short-hand for updating every field.

What else could I try for now to keep my prod app working?

irealva commented 2 months ago

Update this seems to work...

await fetch(
    `https://forms.googleapis.com/v1/forms/${formId}:batchUpdate`,
    {
      method: "POST",
      headers: headers,
      body: JSON.stringify({
        includeFormInResponse: false,
        requests: [
          {
            updateSettings: {
              settings: {
                quizSettings: {
                  isQuiz: true,
                },
              },
              updateMask: "quizSettings.isQuiz",
            },
          },
        ],
      }),
    }
  );
cb-eli commented 2 months ago

I was also using an asterisk in production, seems like Google changed something in the API without saying anything. On the .NET client it was enough to specify quizSettings.

Anyway, happy that it works for now :)