Home > Software design >  I have a question about multiple choice grid in google forms api
I have a question about multiple choice grid in google forms api

Time:12-05

![]:(https://i.stack.imgur.com/5IOEd.png) ![]:(https://i.stack.imgur.com/feAyS.png) How do I write json code? I need an example of writing batchUpdate json in google form api. thank you.

********

  const update = {
        requests: [
            {

                createItem: {
                    item: {
                        title: "TEST ",
                         title: "TEST RADIO",
                        questionGroupItem: {
                            grid: {
                                columns: {
                                    type: "RADIO",
                                    options: [
                                        { value: "A"},
                                        { value: "B"},
                                        { value: "C"},
                                        { value: "D"},
                                    ]
                                }
                            }
                        }
                    },
                    location: { index: 1 },
                },

            }

        ]
    };
const res = await forms.forms.batchUpdate({
        formId: createResponse.data.formId,
        requestBody: update,
    });
********

CodePudding user response:

When I saw your request body, I thought that there are 2 modification points.

  • There are 2 title properties like title: "TEST ", and title: "TEST RADIO",.
  • In your request body, it is required to include rowQuestion of questions.

When these points are reflected in your script, it becomes as follows.

Modified request body:

const update = {
  "requests": [
    {
      "createItem": {
        "item": {
          "title": "TEST ",
          "questionGroupItem": {
            "grid": {
              "columns": {
                "type": "RADIO",
                "options": [
                  {
                    "value": "A"
                  },
                  {
                    "value": "B"
                  },
                  {
                    "value": "C"
                  },
                  {
                    "value": "D"
                  }
                ]
              }
            },
            "questions": [
              {
                "rowQuestion": {
                  "title": "smaple1"
                }
              },
              {
                "rowQuestion": {
                  "title": "sample2"
                }
              }
            ]
          }
        },
        "location": {
          "index": 1
        }
      }
    }
  ]
};
  • In this sample modified request body, 4 columns and 2 rows are created.

References:

  • Related