To add content to a form or update the settings, metadata, or content, use the
batchUpdate()
method, which groups changes together in a batch so that if one
request fails, none of the other (potentially dependent) changes are written.
The batchUpdate()
method returns a response body, within which is a response
for each request. Each response occupies the same index as the corresponding
request; for requests with no applicable response, the response at that index
will be empty.
Before you begin
Perform the following tasks before proceeding with the tasks on this page:
- Complete authorization/authentication and credentials setup in the Early Adopter Program instructions
Update metadata, settings, or items
The following example shows how to update a form's metadata, but the structure
is the same for content and settings—they use the updateItem
or
updateSettings
requests instead of updateFormInfo
. For each request, you
supply the name of the field to be changed and the updated value, along with
an updateMask
value to limit changes to the fields you've specified.
REST
To update the form's description, call the
batchUpdate()
method
with the form ID and the updated description value.
Sample request body
"requests": [{
"updateFormInfo": {
"info": {
"description": "Please complete this quiz based on this week's readings for class."
},
"updateMask": "description"
}
}]
Python
Node.js
Add an item
The following example shows how to add new content to a form. When adding new
content, you must provide a location with an index where new content should be
inserted. For instance, a location with index 0
will insert the content at
the beginning of the form.
REST
To add an item to the form, call the
batchUpdate()
method with the form ID and the item's information and desired location.
Sample request body
"requests": [{
"createItem": {
"item": {
"title": "Homework video",
"description": "Quizzes in Google Forms",
"videoItem": {
"video": {
"youtubeUri": "https://www.youtube.com/watch?v=Lt5HqPvM-eI"
}
}},
"location": {
"index": 0
}
}]
Python
Node.js
Request order
The batchUpdate()
method
accepts an array of sub-requests such as createItem
and updateItem
.
Sub-requests are validated one at a time in the order they are provided.
Example: A batchUpdate
request has a requests
array with two createItem
sub-requests. Sub-request A has location.index
0 and sub-request B has
location.index
1. If the requests
array is [A, B], batchUpdate
will
succeed. If the array is [B, A], batchUpdate
will fail, since location.index
1 is not valid unless the form already contains an item at index 0.