Running a script that accidentally wipes out half your live survey questions is a mistake you only make once.

The Google Forms API makes generating documents easy, but updating or deleting existing items requires much stricter handling.

Because the API treats a form as a live, stateful document, a poorly formatted payload can break routing logic, orphan response data, or scramble your carefully ordered fields.

If you target the wrong index or forget to specify an update mask, the API will overwrite your work without warning.

In this guide, we will look at how to safely target existing form items, apply targeted updates without erasing data, and handle deletions cleanly.

What do you need to configure before updating Google Forms programmatically?

Before you can send a single HTTP request to update or delete a form item, you must configure your Google Cloud project and authenticate your application. The Google Forms API uses OAuth 2.0 to ensure that only authorized users or applications can modify form structures.

Because modifying a form changes its live state, you cannot use read-only permissions. You must request the correct scopes and ensure your application is approved to use them.

  1. Enable the Google Forms API: Navigate to your Google Cloud Console project. Go to APIs & Services, search for the Google Forms API, and click Enable. If you skip this step, all requests will return a 403 error regardless of your authentication status.
  2. Configure OAuth 2.0 credentials: Create an OAuth Client ID for your application. If you are building a server-side application that runs in the background, you will generally need to use a Service Account with domain-wide delegation, as standard Service Accounts cannot easily create or own forms in a standard Google Workspace environment without impersonating a real user.
  3. Set the correct OAuth scopes: Your application must request the https://www.googleapis.com/auth/forms.body scope. This specific scope grants read and write access to the form's structure and items. Do not use the forms.body.readonly scope, as it will explicitly block any batchUpdate requests.
  4. Obtain an access token: Use your Google client library to exchange your credentials for an active bearer token. This token must be included in the Authorization header of every API request you make.
  5. Identify the Form ID: You need the unique identifier of the form you want to modify. You can extract this from the form's edit URL. It is the long string of characters located between /d/ and /edit in the browser address bar.

How do you use batchUpdate to edit existing form items?

To edit an existing question, description, or image, you must send a POST request to the forms.batchUpdate endpoint. The Google Forms API does not use standard REST verbs like PUT or PATCH for individual items.

Instead, every modification is wrapped in a batchUpdate payload. This payload contains an array of requests, allowing you to execute multiple changes in a single network call.

When updating an item, you use the updateItem request type. You must provide the item object with your new values, the location (either by index or itemId) to tell the API which item to change, and a highly specific updateMask.

Expert tip: The updateMask is a comma-separated list of fully qualified JSON paths. If you change a question title but forget to include item.title in the update mask, the API will simply ignore your new title and return a success response, leaving you confused.

Here is how you structure a batchUpdate request to change the title and the required status of an existing multiple-choice question.

POST https://forms.googleapis.com/v1/forms/{formId}:batchUpdate
Authorization: Bearer YOUR_ACCESS_TOKEN
Content-Type: application/json

{
  "requests": [
    {
      "updateItem": {
        "item": {
          "itemId": "1a2b3c4d",
          "title": "Which department do you work in?",
          "questionItem": {
            "question": {
              "required": true,
              "choiceQuestion": {
                "type": "RADIO",
                "options": [
                  {"value": "Sales"},
                  {"value": "Engineering"},
                  {"value": "Marketing"}
                ]
              }
            }
          }
        },
        "location": {
          "index": 2
        },
        "updateMask": "title,questionItem.question.required,questionItem.question.choiceQuestion.options"
      }
    }
  ]
}

Notice the strictness of the updateMask in the payload above. You must map out exactly which nested fields you are touching.

Update Mask configuration

  • ❌ Weak: updateMask: "*"
  • ✅ Strong: updateMask: "title,questionItem.question.required"

Why it works: Using a precise mask ensures you only overwrite the exact fields you intend to change, protecting existing logic like validation rules or image attachments tied to that item.

When you send this payload, the API processes the requests sequentially. If the request succeeds, it returns a BatchUpdateFormResponse object containing the updated form structure or a list of replies confirming the changes.

How do you safely delete questions using the Google Forms API?

Deleting items via the API requires extreme caution. When you remove a question, you are not just altering the visual layout of the form; you are potentially breaking the connection to the underlying response data.

To remove an item, you include a deleteItem object inside your batchUpdate array. The API only needs to know the location of the item you want to destroy.

You can target the item by its absolute index (its position in the form, starting at 0) or by its unique itemId. Using the itemId is significantly safer, especially if another user or script might have added or moved questions recently.

Here is the JSON payload to delete a specific item.

POST https://forms.googleapis.com/v1/forms/{formId}:batchUpdate
Authorization: Bearer YOUR_ACCESS_TOKEN
Content-Type: application/json

{
  "requests": [
    {
      "deleteItem": {
        "location": {
          "index": 4
        }
      }
    }
  ]
}

If you prefer to use the itemId instead of the index, you simply omit the index integer and provide the string ID inside the location object instead.

If the request is successful, the API returns a standard 200 OK status. However, verification is an important step in programmatic deletions.

To verify the deletion was handled correctly:

  1. Check the replies array: The JSON response will contain a replies array that matches the length of your requests array. Ensure there is an empty reply object {} for your deletion request, indicating it passed without errors.
  2. Fetch the form definition: Perform a standard GET request to the form's endpoint.
  3. Inspect the items array: Iterate through the items array in the returned JSON and confirm that the itemId you targeted is no longer present.
  4. Check for broken routing: If the deleted question was used as a navigation target (e.g., "Go to section 2 based on answer"), verify that the form's routing logic has not defaulted to a broken state.

Be aware of the data implications. Deleting a question does not delete the historical responses from a linked Google Sheet, but it does remove the question from the native Google Forms summary charts. If you need to retain the data context visually, consider updating the question title to mark it as archived rather than deleting it entirely.

How do you reorder form items or sync them from an external JSON source?

Reordering form items is notoriously difficult because the operation relies on shifting indices. When you move an item from index 5 to index 1, the item previously at index 1 is pushed down to index 2, and every subsequent item shifts accordingly.

If you are syncing a form from an external database or turning a document into a Google Form, you will often need to reconcile the order of the source material with the live form.

The architectural workflow for syncing order generally follows a specific pattern to avoid index collisions.

Workflow for reordering form items:

  1. Fetch current state: Make a GET request to pull the live form definition and map every itemId to its current index.
  2. Compare with target state: Compare the live array of items against your external JSON source or database sequence.
  3. Calculate moves: Generate a list of required moves.
  4. Execute from bottom to top: Sort your move operations so that you process items moving to higher indices first. This prevents your earlier moves from shifting the target destinations of your later moves.

To perform the actual move, use the moveItem request inside a batchUpdate payload.

{
  "requests": [
    {
      "moveItem": {
        "originalLocation": {
          "index": 5
        },
        "newLocation": {
          "index": 1
        }
      }
    }
  ]
}

The moveItem request requires both the originalLocation and the newLocation. The API will pick up the item at the original index, insert it at the new index, and shift the remaining items down.

When syncing from an external source, always try to anchor your logic on the itemId. If your external JSON source tracks the itemId for each question, you can easily identify when a question has been moved in the source data and issue a corresponding moveItem request to the Google Form.

If your external source does not track IDs and relies purely on text matching, you risk duplicating questions or deleting the wrong items if a user edits a question title slightly.

How do you troubleshoot common Google Forms API batchUpdate errors?

When working with complex JSON payloads, requests will inevitably fail. The Google Forms API returns standard HTTP status codes, but the accompanying JSON error messages contain the actual details you need to fix your script.

Here is a breakdown of the most frequent errors encountered during form updates and how to resolve them.

API Error Code Root Cause Resolution
400 Bad Request The updateMask contains a field path that does not exist in the payload, or the mask is entirely missing. Verify that every field listed in your updateMask exactly matches the nested JSON structure provided in the item object.
400 Bad Request You attempted to set a location.index that is out of bounds (e.g., index 10 on a form with 5 items). Fetch the form first to confirm the length of the items array. Ensure your index is between 0 and items.length.
403 Forbidden The OAuth token lacks the https://www.googleapis.com/auth/forms.body scope, or the API is not enabled. Check your Google Cloud Console to ensure the API is enabled. Re-authenticate the user or service account with the correct write scope.
404 Not Found The formId in the URL or the itemId inside the payload does not exist. Double-check the form ID from the URL. If the form ID is correct, perform a GET request to verify the itemId has not been deleted by another user.
409 Conflict Another user or script updated the form at the exact same time, causing a revision mismatch. Implement the WriteControl object in your request and use exponential backoff to retry the update after fetching the latest revision ID.
429 Too Many Requests Your application has exceeded the write quota limits defined in your Google Cloud project. Slow down your request rate. Group multiple updateItem or deleteItem actions into a single batchUpdate array to reduce HTTP calls.

When you hit a 400 error, the API response body will usually highlight the exact line or field that caused the parsing failure. Pay close attention to the capitalization of fields; the API expects strict camelCase (e.g., questionItem, not question_item).

What are the rate limits and concurrency risks when updating forms?

The Google Forms API enforces strict quotas to maintain system stability. If you treat the API like a high-speed database, you will quickly encounter rate limits or corrupt your form structure through concurrent overwrites.

A common failure mode occurs when two distinct processes attempt to modify the same form simultaneously. Because a form is a single document, one script might delete an item at index 2 just milliseconds before another script tries to update the item at index 2. The second script will fail, or worse, update the wrong item.

To manage these risks, you must structure your application to respect limits and handle concurrency gracefully.

  • Group your operations: Do not send a separate HTTP request for every single question you want to update. The batchUpdate endpoint accepts an array of requests specifically so you can bundle dozens of edits into one network call. This drastically reduces your quota usage.
  • Respect the write limits: By default, the Forms API restricts write operations. Check your specific project quotas in the Google Cloud Console, but plan to throttle your application if you are updating hundreds of forms across an organization.
  • Use the WriteControl object: To prevent concurrent overwrites, include a WriteControl object at the root of your batchUpdate payload. You can provide a requiredRevisionId parameter.
  • Handle revision mismatches: If you provide a requiredRevisionId and the form has been altered by someone else since you last fetched it, the API will reject your request with a 409 Conflict. This protects your data. Your script should then fetch the latest form state, recalculate the necessary changes, and try again.
  • Cache the form state locally: If you are running a complex script that makes sequential updates based on logic, fetch the form once via a GET request, store the JSON in memory, calculate all your required batchUpdate operations against that local state, and send them all at the end.

Implementing WriteControl is the single most effective way to ensure that your automated scripts do not accidentally destroy a form that a human editor is actively working on.

FAQ

Can you update a Google Form item while users are actively submitting responses?

Yes, you can issue batchUpdate requests while a form is live and accepting responses. However, if a user has the form open in their browser, they will not see your changes until they refresh the page. If you delete or alter a question they are currently answering, their submission for that specific field may fail or record inconsistently.

What happens to existing response data when a question is deleted via the API?

When you delete a question, its data disappears from the native "Responses" tab within the Google Forms interface. However, if the form is linked to a Google Sheet, the historical data remains intact in its original column. The column header will remain, but new submissions will simply leave that column blank.

How do you find the itemId of a specific form question programmatically?

You must send a GET request to the https://forms.googleapis.com/v1/forms/{formId} endpoint to retrieve the full form definition. Once you have the JSON response, iterate through the items array. Each object in that array contains an itemId string property alongside its title and question data.

Can you undo a batchUpdate request after it has been executed?

No, the Google Forms API does not offer a programmatic "undo" endpoint or a version history restoration feature via the API. Once a batchUpdate returns a success response, the changes are permanent. You must maintain your own backups or external state if you need the ability to revert a form to a previous layout.

Managing Google Forms via the API gives you total control over your surveys and assessments, but that power requires careful error handling and precise JSON construction. If you are regularly generating complex forms from unstructured text or external briefs, and you want to avoid writing manual batchUpdate payloads entirely, tools like Doc2Form can automatically convert a description into a Google Form directly in your Drive. Whichever method you choose, always verify your indices, lock down your update masks, and test your destructive actions on a duplicate form first.