{
  "name": "PDF to Google Forms Quiz Generator",
  "nodes": [
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "gpt-4o-mini"
        },
        "responsesApiEnabled": false,
        "options": {
          "timeout": 500000
        }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        112,
        1248
      ],
      "id": "8a16b13f-bc17-4d70-a084-af8bf79f4872",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "SsnwT4koLkkkT1th",
          "name": "OpenAI account"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://forms.googleapis.com/v1/forms",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "googleOAuth2Api",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "{\n  \"info\": {\n    \"title\": \"My Quiz Form\",\n    \"documentTitle\": \"Quiz Form\"\n  }\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        432,
        1024
      ],
      "id": "12b48d3a-afc2-4fe8-9be6-759cf785b952",
      "name": "Create Form",
      "credentials": {
        "httpHeaderAuth": {
          "id": "69ilqzcKEgbblIga",
          "name": "Http Header Auth account"
        },
        "googleOAuth2Api": {
          "id": "MWa38DNDqpHT7eWr",
          "name": "Google account"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://forms.googleapis.com/v1/forms/{{ $('Create Form').item.json.formId }}:batchUpdate",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "googleOAuth2Api",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "{\n  \"requests\": [\n    {\n      \"updateSettings\": {\n        \"settings\": {\n          \"quizSettings\": {\n            \"isQuiz\": true\n          }\n        },\n        \"updateMask\": \"quizSettings.isQuiz\"\n      }\n    }\n  ]\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        608,
        1024
      ],
      "id": "21eb0af7-727d-4018-9205-bd3ac363d233",
      "name": "Enable Quiz Mode",
      "credentials": {
        "httpHeaderAuth": {
          "id": "69ilqzcKEgbblIga",
          "name": "Http Header Auth account"
        },
        "googleOAuth2Api": {
          "id": "MWa38DNDqpHT7eWr",
          "name": "Google account"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://forms.googleapis.com/v1/forms/{{ $('Create Form').item.json.formId }}:batchUpdate",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "googleOAuth2Api",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $('Questions Generate').item.json.output }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        768,
        1024
      ],
      "id": "daf1742d-4476-4d7c-a493-203a372a7988",
      "name": "Add Questions",
      "credentials": {
        "googleOAuth2Api": {
          "id": "MWa38DNDqpHT7eWr",
          "name": "Google account"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://forms.googleapis.com/v1/forms/{{ $('Create Form').item.json.formId }}:batchUpdate",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "googleOAuth2Api",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"requests\": [\n    {\n      \"createItem\": {\n        \"item\": {\n          \"title\": \"Student Information\",\n          \"description\": \"Please fill in your details before starting the quiz\",\n          \"pageBreakItem\": {}\n        },\n        \"location\": { \"index\": 0 }\n      }\n    },\n    {\n      \"createItem\": {\n        \"item\": {\n          \"title\": \"Full Name\",\n          \"questionItem\": {\n            \"question\": {\n              \"required\": true,\n              \"textQuestion\": { \"paragraph\": false }\n            }\n          }\n        },\n        \"location\": { \"index\": 1 }\n      }\n    },\n    {\n      \"createItem\": {\n        \"item\": {\n          \"title\": \"Email Address\",\n          \"questionItem\": {\n            \"question\": {\n              \"required\": true,\n              \"textQuestion\": { \"paragraph\": false }\n            }\n          }\n        },\n        \"location\": { \"index\": 2 }\n      }\n    },\n    {\n      \"createItem\": {\n        \"item\": {\n          \"title\": \"Student ID\",\n          \"questionItem\": {\n            \"question\": {\n              \"required\": true,\n              \"textQuestion\": { \"paragraph\": false }\n            }\n          }\n        },\n        \"location\": { \"index\": 3 }\n      }\n    },\n    {\n      \"createItem\": {\n        \"item\": {\n          \"title\": \"Class/Grade\",\n          \"questionItem\": {\n            \"question\": {\n              \"required\": true,\n              \"textQuestion\": { \"paragraph\": false }\n            }\n          }\n        },\n        \"location\": { \"index\": 4 }\n      }\n    },\n    {\n      \"createItem\": {\n        \"item\": {\n          \"title\": \"Quiz Questions\",\n          \"description\": \"Answer all questions to the best of your ability\",\n          \"pageBreakItem\": {}\n        },\n        \"location\": { \"index\": 5 }\n      }\n    }\n  ]\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        928,
        1024
      ],
      "id": "047592f0-9cfa-480f-ab63-a4b4651b8793",
      "name": "Add Student Details",
      "credentials": {
        "googleOAuth2Api": {
          "id": "MWa38DNDqpHT7eWr",
          "name": "Google account"
        }
      }
    },
    {
      "parameters": {
        "operation": "pdf",
        "binaryPropertyName": "PDF",
        "options": {}
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1.1,
      "position": [
        -32,
        1024
      ],
      "id": "0967394c-7dd2-4e31-929c-4ea9dd7676f4",
      "name": "Extract from File"
    },
    {
      "parameters": {
        "jsonSchemaExample": "{\n  \"requests\": [\n    {\n      \"createItem\": {\n        \"item\": {\n          \"title\": \"Question text here?\",\n          \"questionItem\": {\n            \"question\": {\n              \"required\": true,\n              \"grading\": {\n                \"pointValue\": 1,\n                \"correctAnswers\": {\n                  \"answers\": [\n                    {\n                      \"value\": \"Correct answer text\"\n                    }\n                  ]\n                },\n                \"whenRight\": {\n                  \"text\": \"Correct! Well done.\"\n                },\n                \"whenWrong\": {\n                  \"text\": \"Incorrect. The correct answer is [correct answer].\"\n                }\n              },\n              \"choiceQuestion\": {\n                \"type\": \"RADIO\",\n                \"options\": [\n                  { \"value\": \"Option 1\" },\n                  { \"value\": \"Option 2 (correct)\" },\n                  { \"value\": \"Option 3\" },\n                  { \"value\": \"Option 4\" }\n                ],\n                \"shuffle\": true\n              }\n            }\n          }\n        },\n        \"location\": {\n          \"index\": 0\n        }\n      }\n    }\n  ]\n}"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        272,
        1248
      ],
      "id": "8be0c42f-bc59-4d92-ab09-cc56e52b7cc4",
      "name": "Structured Output Parser",
      "notesInFlow": false
    },
    {
      "parameters": {
        "formTitle": "PDF",
        "formFields": {
          "values": [
            {
              "fieldLabel": "PDF",
              "fieldType": "file",
              "acceptFileTypes": ".pdf",
              "requiredField": true
            },
            {
              "fieldLabel": "How many questions would you like to have in the quiz?",
              "placeholder": "e.g. 20",
              "requiredField": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.3,
      "position": [
        -208,
        1024
      ],
      "id": "b78c809d-0d5a-47a5-9fc3-af8885203f3c",
      "name": "On form submission",
      "webhookId": "4a186769-ef3a-48b1-9b3e-b612c2da7497"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=You are an AI Teacher Agent specialized in creating quiz questions from educational content.\n\nInput : {{ $json.text }}\n\nYour Task:\nGenerate multiple-choice quiz questions with correct answers that can be directly used with Google Forms API.\nRequirements:\n\nCreate at least {{ $('On form submission').item.json['How many questions would you like to have in the quiz?'] }} questions based on the content\nEach question must have exactly 4 options\nMark one option as the correct answer\nEach question is worth 1 point\nFocus on key concepts, important facts, and learning objectives\nUse clear, student-friendly language\nAvoid ambiguous or trick questions\nDon't repeat similar questions\n\nReturn a valid JSON object with this exact structure:\n{\n  \"requests\": [\n    {\n      \"createItem\": {\n        \"item\": {\n          \"title\": \"Question text here?\",\n          \"questionItem\": {\n            \"question\": {\n              \"required\": true,\n              \"grading\": {\n                \"pointValue\": 1,\n                \"correctAnswers\": {\n                  \"answers\": [\n                    {\n                      \"value\": \"Correct answer text\"\n                    }\n                  ]\n                },\n                \"whenRight\": {\n                  \"text\": \"Correct! Well done.\"\n                },\n                \"whenWrong\": {\n                  \"text\": \"Incorrect. The correct answer is [correct answer].\"\n                }\n              },\n              \"choiceQuestion\": {\n                \"type\": \"RADIO\",\n                \"options\": [\n                  { \"value\": \"Option 1\" },\n                  { \"value\": \"Option 2 (correct)\" },\n                  { \"value\": \"Option 3\" },\n                  { \"value\": \"Option 4\" }\n                ],\n                \"shuffle\": true\n              }\n            }\n          }\n        },\n        \"location\": {\n          \"index\": 0\n        }\n      }\n    }\n  ]\n}\n\nImportant Notes:\n\nThe correct answer in correctAnswers.answers[0].value must EXACTLY match one of the option values in options\nUse \"shuffle\": true to randomize option order for students\nCustomize whenWrong.text to include the correct answer\nIndex starts at 0 and increments for each question\nEnsure all JSON is properly formatted and valid\n\nQuestion Quality Guidelines:\n\nTest understanding, not just memorization\nUse varied question stems (What, Why, How, Which, etc.)\nInclude questions at different difficulty levels\nEnsure distractors (wrong answers) are plausible but clearly incorrect\nAvoid \"all of the above\" or \"none of the above\" options",
        "hasOutputParser": true,
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.7,
      "position": [
        128,
        1024
      ],
      "id": "5607de4a-faaa-4245-a3c0-46823d53f6da",
      "name": "Questions Generate"
    },
    {
      "parameters": {
        "jsCode": "// Get question array\nconst data = $('Questions Generate').first().json.output.requests;\n\n// Get quiz URL from previous node\nconst quizUrl = $('Create Form').first().json.responderUri|| \"\";\n\n// Prepare rows\nlet rows = [];\n\nfor (let i = 0; i < data.length; i++) {\n  const req = data[i];\n\n  const item = req.createItem.item;\n  const question = item.title;\n  const options = item.questionItem.question.choiceQuestion.options.map(o => o.value);\n  const correctAnswer = item.questionItem.question.grading.correctAnswers.answers[0].value;\n\n  rows.push({\n    question: question,\n    option1: options[0] || \"\",\n    option2: options[1] || \"\",\n    option3: options[2] || \"\",\n    option4: options[3] || \"\",\n    correct_answer: correctAnswer,\n\n    // ⭐ ONLY FIRST ROW gets quiz URL\n    quiz_url: i === 0 ? quizUrl : \"\"\n  });\n}\n\n// Return to Sheet node\nreturn rows.map(r => ({ json: r }));"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1104,
        1024
      ],
      "id": "202d820a-a296-4f42-a7f3-e0ce6409f121",
      "name": "Set a Google Sheet Structure for all Questions"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1mpAObyL-Un8_369o1omQSzr415lyW3HxstODO41DHTQ",
          "mode": "list",
          "cachedResultName": "My Quiz Form"
        },
        "sheetName": {
          "__rl": true,
          "value": 1003708851,
          "mode": "list",
          "cachedResultName": "Quiz Form"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Question": "={{ $json.question }}",
            "Option1": "={{ $json.option1 }}",
            "Option2": "={{ $json.option2 }}",
            "Option3": "={{ $json.option3 }}",
            "Option4": "={{ $json.option4 }}",
            "Correct_answer": "={{ $json.correct_answer }}",
            "Quiz Url": "={{ $json.quiz_url }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Question",
              "displayName": "Question",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Option1",
              "displayName": "Option1",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Option2",
              "displayName": "Option2",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Option3",
              "displayName": "Option3",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Option4",
              "displayName": "Option4",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Correct_answer",
              "displayName": "Correct_answer",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Quiz Url",
              "displayName": "Quiz Url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1280,
        1024
      ],
      "id": "fb4d2a7e-71b4-4f19-bb88-456d531364fd",
      "name": "Append All Questions",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "GojUvCMDXbhY8HrB",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "content": "## Google sheet\nCreate your own spreadsheet with these tabs/columns, then select it in the Google Sheets nodes:\n- **My Quiz Form → Quiz Form**: `Question`, `Option1`, `Option2`, `Option3`, `Option4`, `Correct_answer`, `Quiz Url`"
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -256,
        832
      ],
      "id": "6dad6bad-2214-43d4-92f7-2cb9521dbfc6",
      "name": "Sticky Note"
    }
  ],
  "pinData": {},
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Questions Generate",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Create Form": {
      "main": [
        [
          {
            "node": "Enable Quiz Mode",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enable Quiz Mode": {
      "main": [
        [
          {
            "node": "Add Questions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Questions": {
      "main": [
        [
          {
            "node": "Add Student Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Student Details": {
      "main": [
        [
          {
            "node": "Set a Google Sheet Structure for all Questions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Questions Generate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Questions Generate",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "On form submission": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Questions Generate": {
      "main": [
        [
          {
            "node": "Create Form",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set a Google Sheet Structure for all Questions": {
      "main": [
        [
          {
            "node": "Append All Questions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "7130de2f-dc58-47aa-a829-8d36d1917c32",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "f1c26778ec36097a9722a22c47c5e9c01f00b8862dadd0121ec118026a370fa6"
  },
  "id": "r2LvOqDq2Obojufc",
  "tags": []
}