---
title: "Convert Google Docs to Moodle Quizzes Programmatically | Formswrite Blog"
description: "Automate Moodle quiz creation from Google Docs using the Formswrite REST API. Import quizzes as Moodle XML with a single API call. Code examples in..."
canonical: https://formswrite.com/blog/convert-google-docs-to-moodle-quiz-api-programmatically
last-updated: 2026-02-15
---

# Convert Google Docs to Moodle Quizzes Programmatically

In short

Creating quizzes in Moodle is slow. You have to manually enter each question, configure answer choices, set point values, and assign feedback - one question at a time. If you already have your quiz content in a Google Doc, why not automate the whole process?

## Convert Google Docs to Moodle Quizzes Programmatically with the Formswrite API

The **Formswrite API** lets you convert any Google Doc into a **Moodle XML file** with a single API call. The AI reads your document, extracts questions and answers, and generates a ready-to-import Moodle quiz file.

---

## How It Works

1.  **Write your quiz** in a Google Doc (multiple choice, true/false, short answer, etc.)
2.  **Call the API** with your document ID and `format: "moodle"`
3.  **Download the Moodle XML** file from the response URL
4.  **Import into Moodle** via Site Administration → Question Bank → Import

That's it. No manual data entry. No copy-paste errors.

---

## Quick Start

### cURL

bash`curl -X POST https://api.formswrite.com/api/v1/convert \   -H "Authorization: Bearer YOUR_API_TOKEN" \   -H "Content-Type: application/json" \   -d '{     "documentId": "YOUR_GOOGLE_DOC_ID",     "format": "moodle",     "documentName": "Biology Midterm Exam"   }'`

### Response

json`{   "success": true,   "exportId": "export-uuid-here",   "downloadUrl": "https://api.formswrite.com/api/forms/exports/export-uuid-here",   "fileName": "Biology Midterm Exam-moodle.xml",   "format": "moodle",   "expiresAt": "2026-03-17T00:00:00.000Z" }`

Download the file from `downloadUrl` and import it into Moodle. The XML file is valid Moodle XML with all question types, answer options, correct answers, and point values included.

---

## Python Example

python`import requests  API_TOKEN = "your_api_token_here"  # Convert Google Doc to Moodle XML response = requests.post(     "https://api.formswrite.com/api/v1/convert",     headers={         "Authorization": f"Bearer {API_TOKEN}",         "Content-Type": "application/json"     },     json={         "documentId": "1abc123xyz",         "format": "moodle",         "documentName": "Chapter 5 Quiz"     } )  result = response.json()  if result["success"]:     # Download the Moodle XML file     xml_response = requests.get(result["downloadUrl"])     with open(result["fileName"], "wb") as f:         f.write(xml_response.content)     print(f"Moodle XML saved: {result['fileName']}")`

---

## Node.js Example

javascript``const fs = require('fs');  async function convertToMoodle(docId, name) {   const response = await fetch('https://api.formswrite.com/api/v1/convert', {     method: 'POST',     headers: {       'Authorization': `Bearer ${process.env.FORMSWRITE_API_TOKEN}`,       'Content-Type': 'application/json'     },     body: JSON.stringify({       documentId: docId,       format: 'moodle',       documentName: name     })   });    const result = await response.json();    if (result.success) {     // Download the Moodle XML     const xmlResponse = await fetch(result.downloadUrl);     const buffer = await xmlResponse.arrayBuffer();     fs.writeFileSync(result.fileName, Buffer.from(buffer));     console.log(`Saved: ${result.fileName}`);   } }  convertToMoodle('1abc123xyz', 'Biology Quiz');``

---

## Supported Moodle Formats

The Formswrite API supports multiple Moodle-compatible output formats:

| Format | API Value | File Type | Best For |
| --- | --- | --- | --- |
| Moodle XML | moodle | .xml | Standard Moodle quiz import |
| GIFT | gift | .txt | Lightweight text-based format |
| Aiken | aiken | .txt | Simple multiple-choice only |
| Cloze | cloze | .txt | Fill-in-the-blank questions |
| H5P | h5p | .zip | Interactive content |
| QTI 2.1 | qti_21 | .zip | IMS standard (cross-platform) |

Just change the `format` parameter to switch between them.

---

## Supported Question Types

The AI automatically detects these question types from your Google Doc:

-   **Multiple Choice** - single correct answer
-   **Multiple Select** (Checkboxes) - multiple correct answers
-   **True/False** - binary choice
-   **Short Answer** - text input
-   **Essay / Paragraph** - long-form response
-   **Matching** - pair items together
-   **Fill in the Blank** (Cloze) - embedded answers
-   **Numerical** - number-based answers

Correct answers, point values, and feedback are all extracted automatically when present in your document.

---

## Batch Conversion

Need to convert multiple Google Docs to Moodle quizzes? Loop through your documents:

python`documents = [     {"id": "doc_id_1", "name": "Quiz 1 - Cell Biology"},     {"id": "doc_id_2", "name": "Quiz 2 - Genetics"},     {"id": "doc_id_3", "name": "Quiz 3 - Evolution"}, ]  for doc in documents:     response = requests.post(         "https://api.formswrite.com/api/v1/convert",         headers={             "Authorization": f"Bearer {API_TOKEN}",             "Content-Type": "application/json"         },         json={             "documentId": doc["id"],             "format": "moodle",             "documentName": doc["name"]         }     )     result = response.json()     if result["success"]:         xml = requests.get(result["downloadUrl"])         with open(result["fileName"], "wb") as f:             f.write(xml.content)         print(f"Converted: {doc['name']}")`

---

## Use Cases

-   **Universities** automating end-of-semester exam creation from faculty Google Docs
-   **Corporate training** teams converting onboarding documents to Moodle assessments
-   **K-12 schools** batch-importing weekly quizzes from teacher-created documents
-   **EdTech platforms** integrating Moodle quiz generation into their product
-   **LMS administrators** building automated content pipelines

---

## FAQ

### Can I import the generated XML directly into Moodle?

Yes. The generated file follows the standard Moodle XML format. Go to Site Administration → Question Bank → Import → Moodle XML format, and upload the file.

### Does it preserve images from my Google Doc?

Yes. Images embedded in your Google Doc are extracted and included in the Moodle XML as base64-encoded data or external URLs.

### Can I convert to other LMS formats with the same API?

Absolutely. Change `format` to `canvas`, `blackboard`, `brightspace`, `schoology`, or `sakai` to generate files for other learning management systems.

### What if my document is very large?

Use `async: true` in your request body. The API will return a `jobId` immediately, and you can poll `/api/v1/convert/status/:jobId` for the result.

### Do I need a Moodle plugin to use this?

No. The Formswrite API is a standalone service. You generate the Moodle XML file via the API and import it through Moodle's built-in import feature.

---

## Get Started

Stop manually entering quiz questions into Moodle. **Sign up for Formswrite** and start converting your Google Docs to Moodle quizzes programmatically.

## Related posts

-   [Formswrite API Reference: Documents to Forms and Quizzes](/blog/formswrite-api-documentation-reference): Complete API reference for Formswrite. Convert Google Docs to Google Forms, Moodle, Canvas, Kahoot, and 25+ formats programmatically. REST API with...
-   [Document to Quiz Conversion API: Complete Developer Guide](/blog/document-to-quiz-conversion-api-developer-guide): Complete developer guide for the Formswrite REST API. Convert Google Docs to quizzes and forms in 25+ formats including Google Forms, Moodle, Canvas...

## Related guides

-   [Convert Any Document to Moodle Quizzes](/product/documents-to-moodle)
-   [Zapier + Formswrite: Automate Google Forms and Quiz Creation](/blog/zapier-formswrite-api-automate-google-forms-creation)
