Untuk memberi pembuat formulir kontrol yang lebih besar atas siapa yang dapat merespons, kami memperkenalkan kontrol terperinci untuk responden. Formulir yang dibuat dengan API setelah 31 Januari 2026 akan memiliki status tidak dipublikasikan secara default. Untuk mempelajari lebih lanjut, lihat
Perubahan API pada Google Formulir.
Membuat formulir atau kuis
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menjelaskan cara melakukan tugas berikut yang melibatkan formulir:
- Membuat formulir baru
- Menduplikasi formulir yang ada
- Mengonversi formulir menjadi kuis
Sebelum memulai
Lakukan tugas berikut sebelum melanjutkan tugas di halaman ini:
- Selesaikan otorisasi atau autentikasi dan penyiapan kredensial dalam petunjuk
Program Pengguna Awal.
- Baca ringkasan Forms API.
Pembuatan awal formulir hanya memerlukan kolom judul—kolom lain dalam permintaan akan diabaikan. Untuk membuat konten dan metadata
formulir atau melakukan pembaruan, gunakan metode batchUpdate()
. Lihat artikel
Memperbarui formulir atau kuis untuk mengetahui informasi
selengkapnya.
REST
Panggil metode forms.create()
hanya dengan judul.
Contoh isi permintaan
{
"info": {
"title": "My new form"
}
}
Anda dapat menduplikasi formulir yang ada dengan
Google Drive API untuk mempermudah
penggunaan kembali konten. Anda dapat menemukan ID formulir di URL Google Formulir:
https://docs.google.com/forms/d/FORM_ID/edit
REST
Panggil metode
files.copy()
Google Drive API dengan ID formulir yang ingin Anda salin.
Untuk membuat kuis, buat formulir terlebih dahulu seperti yang dijelaskan di Membuat formulir baru,
lalu perbarui setelan formulir. Pembaruan memerlukan ID formulir.
REST
Panggil metode
batch.update()
pada formulir yang ada untuk menetapkan setelan isQuiz
ke benar.
Contoh isi permintaan
{
"requests": [
{
"updateSettings": {
"settings": {
"quizSettings": {
"isQuiz": True
}
},
"updateMask": "quizSettings.isQuiz"
}
}
]
}
Langkah berikutnya
Berikut beberapa langkah berikutnya yang dapat Anda coba:
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-06-27 UTC.
[null,null,["Terakhir diperbarui pada 2025-06-27 UTC."],[],["This document details how to create, duplicate, and convert forms. To create a new form, use the `forms.create()` method with a title. To duplicate a form, employ the Drive API's `files.copy()` method, specifying the form's ID. To convert a form into a quiz, use the `batch.update()` method to change the `isQuiz` setting to true, also requires the form ID. Authorization and authentication setup as indicated in the instructions is required.\n"],null,["# Create a form or quiz\n\nThis page describes how to perform these tasks involving forms:\n\n- Create a new form\n- Duplicate an existing form\n- Convert a form to a quiz\n\nBefore you begin\n----------------\n\nDo the following tasks before proceeding with the tasks on this page:\n\n- Complete authorization or authentication and credentials setup in the Early Adopter Program instructions.\n- Read the [Forms API overview](/workspace/forms/api/guides).\n\nCreate a new form\n-----------------\n\nThe initial creation of a form only requires a title field---any other fields\nin the request will be ignored. To build out the content and metadata of a\nform or make updates, use the `batchUpdate()` method. See\n[Update a form or quiz](/workspace/forms/api/guides/update-form-quiz) for more\ninformation. \n\n### REST\n\nCall the [`forms.create()`](/workspace/forms/api/reference/rest/v1/forms/create)\nmethod with only a title.\n\n**Sample request body** \n\n {\n \"info\": {\n \"title\": \"My new form\"\n }\n }\n\n### Python\n\nforms/snippets/create_form.py \n[View on GitHub](https://github.com/googleworkspace/python-samples/blob/main/forms/snippets/create_form.py) \n\n```python\nfrom apiclient import discovery\nfrom httplib2 import Http\nfrom oauth2client import client, file, tools\n\nSCOPES = \"https://www.googleapis.com/auth/drive\"\nDISCOVERY_DOC = \"https://forms.googleapis.com/$discovery/rest?version=v1\"\n\nstore = file.Storage(\"token.json\")\ncreds = None\nif not creds or creds.invalid:\n flow = client.flow_from_clientsecrets(\"client_secrets.json\", SCOPES)\n creds = tools.run_flow(flow, store)\n\nform_service = discovery.build(\n \"forms\",\n \"v1\",\n http=creds.authorize(Http()),\n discoveryServiceUrl=DISCOVERY_DOC,\n static_discovery=False,\n)\n\nform = {\n \"info\": {\n \"title\": \"My new form\",\n },\n}\n# Prints the details of the sample form\nresult = form_service.forms().create(body=form).execute()\nprint(result)\n```\n\n### Node.js\n\nforms/snippets/create_form.js \n[View on GitHub](https://github.com/googleworkspace/node-samples/blob/main/forms/snippets/create_form.js) \n\n```javascript\n'use strict';\n\nconst path = require('path');\nconst google = require('@googleapis/forms');\nconst {authenticate} = require('@google-cloud/local-auth');\n\nasync function runSample(query) {\n const authClient = await authenticate({\n keyfilePath: path.join(__dirname, 'credentials.json'),\n scopes: 'https://www.googleapis.com/auth/drive',\n });\n const forms = google.forms({\n version: 'v1',\n auth: authClient,\n });\n const newForm = {\n info: {\n title: 'Creating a new form in Node',\n },\n };\n const res = await forms.forms.create({\n requestBody: newForm,\n });\n console.log(res.data);\n return res.data;\n}\n\nif (module === require.main) {\n runSample().catch(console.error);\n}\nmodule.exports = runSample;\n```\n\nDuplicate an existing form\n--------------------------\n\nYou can duplicate an existing form with the\n[Google Drive API](/workspace/drive/api/v3/about-sdk) to make content re-use\neasier. You can find the form ID in a Google Forms URL:\n\n`https://docs.google.com/forms/d/FORM_ID/edit` \n\n### REST\n\nCall the Google Drive API's\n[`files.copy()`](/workspace/drive/v3/reference/files/copy)\nmethod with the ID of the form you want to copy.\n\n### Python\n\nforms/snippets/duplicate_form.py \n[View on GitHub](https://github.com/googleworkspace/python-samples/blob/main/forms/snippets/duplicate_form.py) \n\n```python\nimport os.path\n\nfrom google.auth.transport.requests import Request\nfrom google.oauth2.credentials import Credentials\nfrom google_auth_oauthlib.flow import InstalledAppFlow\nfrom googleapiclient.discovery import build\n\n# If modifying these scopes, delete the file token.json.\nSCOPES = [\"https://www.googleapis.com/auth/drive\"]\n\n\ndef main():\n \"\"\"Shows copy file example in Drive v3 API.\n Prints the name, id and other data of the copied file.\n \"\"\"\n creds = None\n if os.path.exists(\"token.json\"):\n creds = Credentials.from_authorized_user_file(\"token.json\", SCOPES)\n # If there are no (valid) credentials available, let the user log in.\n if not creds or not creds.valid:\n if creds and creds.expired and creds.refresh_token:\n creds.refresh(Request())\n else:\n flow = InstalledAppFlow.from_client_secrets_file(\n \"client_secrets.json\", SCOPES\n )\n creds = flow.run_local_server(port=0)\n # Save the credentials for the next run\n with open(\"token.json\", \"w\") as token:\n token.write(creds.to_json())\n\n service = build(\"drive\", \"v3\", credentials=creds)\n\n # Call the Drive v3 API\n origin_file_id = \"1ox-6vHFeKpC6mon-tL5ygBC8zpbTnTp76JCZdIg80hA\" # example ID\n copied_file = {\"title\": \"my_copy\"}\n results = (\n service.files().copy(fileId=origin_file_id, body=copied_file).execute()\n )\n print(results)\n\n\nif __name__ == \"__main__\":\n main()\n```\n\nConvert a form to a quiz\n------------------------\n\nTo create a quiz, first create a form as described in [Create a new form](#create_a_new_form),\nthen update the form's settings. The update requires the form ID. \n\n### REST\n\nCall the\n[`batch.update()`](/workspace/forms/api/reference/rest/v1/forms/batchUpdate)\nmethod on an existing form to set the `isQuiz` setting to true.\n\n**Sample request body** \n\n {\n \"requests\": [\n {\n \"updateSettings\": {\n \"settings\": {\n \"quizSettings\": {\n \"isQuiz\": True\n }\n },\n \"updateMask\": \"quizSettings.isQuiz\"\n }\n }\n ]\n }\n\n### Python\n\nforms/snippets/convert_form.py \n[View on GitHub](https://github.com/googleworkspace/python-samples/blob/main/forms/snippets/convert_form.py) \n\n```python\nfrom apiclient import discovery\nfrom httplib2 import Http\nfrom oauth2client import client, file, tools\n\nSCOPES = \"https://www.googleapis.com/auth/forms.body\"\nDISCOVERY_DOC = \"https://forms.googleapis.com/$discovery/rest?version=v1\"\n\nstore = file.Storage(\"token.json\")\ncreds = None\nif not creds or creds.invalid:\n flow = client.flow_from_clientsecrets(\"client_secrets.json\", SCOPES)\n creds = tools.run_flow(flow, store)\n\nform_service = discovery.build(\n \"forms\",\n \"v1\",\n http=creds.authorize(Http()),\n discoveryServiceUrl=DISCOVERY_DOC,\n static_discovery=False,\n)\n\nform = {\n \"info\": {\n \"title\": \"My new quiz\",\n }\n}\n\n# Creates the initial form\nresult = form_service.forms().create(body=form).execute()\n\n# JSON to convert the form into a quiz\nupdate = {\n \"requests\": [\n {\n \"updateSettings\": {\n \"settings\": {\"quizSettings\": {\"isQuiz\": True}},\n \"updateMask\": \"quizSettings.isQuiz\",\n }\n }\n ]\n}\n\n# Converts the form into a quiz\nquestion_setting = (\n form_service.forms()\n .batchUpdate(formId=result[\"formId\"], body=update)\n .execute()\n)\n\n# Print the result to see it's now a quiz\ngetresult = form_service.forms().get(formId=result[\"formId\"]).execute()\nprint(getresult)\n```\n\n### Node.js\n\nforms/snippets/convert_form.js \n[View on GitHub](https://github.com/googleworkspace/node-samples/blob/main/forms/snippets/convert_form.js) \n\n```javascript\n'use strict';\n\nconst path = require('path');\nconst google = require('@googleapis/forms');\nconst {authenticate} = require('@google-cloud/local-auth');\n\nasync function runSample(query) {\n const authClient = await authenticate({\n keyfilePath: path.join(__dirname, 'credentials.json'),\n scopes: 'https://www.googleapis.com/auth/drive',\n });\n const forms = google.forms({\n version: 'v1',\n auth: authClient,\n });\n const newForm = {\n info: {\n title: 'Creating a new form for batchUpdate in Node',\n },\n };\n const createResponse = await forms.forms.create({\n requestBody: newForm,\n });\n console.log('New formId was: ' + createResponse.data.formId);\n\n // Request body to convert form to a quiz\n const updateRequest = {\n requests: [\n {\n updateSettings: {\n settings: {\n quizSettings: {\n isQuiz: true,\n },\n },\n updateMask: 'quizSettings.isQuiz',\n },\n },\n ],\n };\n const res = await forms.forms.batchUpdate({\n formId: createResponse.data.formId,\n requestBody: updateRequest,\n });\n console.log(res.data);\n return res.data;\n}\n\nif (module === require.main) {\n runSample().catch(console.error);\n}\nmodule.exports = runSample;\n```\n\nNext steps\n----------\n\nHere are a few next steps you might try:\n\n- To add or update form content, refer to [Update a form or quiz](/workspace/forms/api/guides/update-form-quiz).\n- To view form information or responses, refer to [Retrieve forms and responses](/workspace/forms/api/guides/retrieve-forms-responses).\n- To publish the form and manage responders, refer to [Publish and manage responders](/workspace/forms/api/guides/publish-form)."]]