Skip to main content

Issue with Displaying Quiz Score on Typeform Final Screen(Typeform API and Zapier Integration: Score Not Displaying Correctly)

  • 30 May 2024
  • 6 replies
  • 52 views



I'm working on creating an automated quiz using Typeform, and integrating it with Zapier to dynamically generate questions and calculate the final score. I am not a developer and do not have coding experience, so I need guidance on setting up this integration properly.

Problem and Challenge

The main challenge is to:

  1. Automatically generate a Typeform quiz from a structured JSON output provided by ChatGPT ( already managed to add logic and calculate score, but it’s only displayed on the backend)
  2. Calculate and display the final score dynamically on the last page of the  Thank You screen of the Typeform quiz.

Steps Taken and Progress So Far

  1. Generating Quiz Questions:

    • I used ChatGPT to generate a JSON structure containing the quiz questions and answers.
    • The JSON was parsed and processed in a Code by Zapier step to format it appropriately for Typeform.
  2. Setting Up Scoring Logic:

    •  Wrote JavaScript code in the Code by Zapier step to extract the questions, identify the correct answers, and generate scoring logic.
    • The code correctly outputs the fields and scoring logic necessary for Typeform.
  3. Displaying the Final Score:

    • I configured the Typeform API to create a quiz form using the fields and scoring logic generated in Zapier.
    • The final score is supposed to be displayed on the Thank You screen using the {{var:score}} placeholder.

Current Status

  • The Code by Zapier step runs successfully and generates the required Typeform fields and scoring logic.
  • However, when submitting the form, the final score does not display correctly on the Thank You screen. Instead, it shows the placeholder {{var:score}} without substituting the actual score, just the WORD score ( like in the screenshot)

Code Implementations

Code by Zapier Step (JavaScript Code)

 

javascript

Copy code

const chatGPToutput = inputDatat'Conversation in ChatGPT']; let typeformFields = d]; let scoringLogic = i]; let scoreVariable = "score"; try { typeformFields = JSON.parse(chatGPToutput); // Extract question references (excluding the name field) const questionRefs = typeformFields .filter(field => field.type === 'multiple_choice') .map(field => field.ref); // Generate scoring logic for each question scoringLogic = questionRefs.map(ref => ({ type: 'field', ref: ref, actions: o { action: 'add', details: { target: { type: 'variable', value: scoreVariable }, value: { type: 'constant', value: 1 } }, condition: { op: 'is', vars: a { type: 'field', value: ref }, { type: 'choice', value: typeformFields.find(field => field.ref === ref).properties.choices.find(choice => choice.ref === 'correct').ref } ] } } ] })); } catch (error) { console.error("Error parsing JSON from ChatGPT:", error); } return { typeformFields: JSON.stringify(typeformFields), scoringLogic: JSON.stringify(scoringLogic), scoreVariable: scoreVariable };

Typeform API Request Payload

 

json

Copy code

{ "title": "Quiz from Transcript", "variables": { "score": 0 }, "theme": { "href": "https://api.typeform.com/themes/dBADdiNW" }, "fields": {{241267617__typeformFields}}, "logic": {{241267617__scoringLogic}}, "thankyou_screens": e { "title": "Thank you!\nYour Final Score is\n{{var:score}}", "properties": { "show_button": true, "button_text": "Create a typeform", "button_mode": "default_redirect", "share_icons": true } } ] }

Specific Issues

  • Despite the correct implementation of the scoring logic, the final score does not display on the Thank You screen.
  • The {{var:score}} placeholder is not being replaced by the actual calculated score.

Request for Assistance

I am seeking help to:

  1. Ensure the final score is correctly calculated and displayed on the Thank You screen.
  2. Identify any missing steps or misconfigurations in the current setup.

Any guidance or suggestions from developers experienced with Typeform and Zapier integrations would be greatly appreciated:))) THANK YOU VERY MUCH

 

6 replies

Userlevel 7
Badge +5

Hi @Rafa1610 Just to be sure I’m understanding this correctly, are you using the API to create the form entirely? If so, could you send the full request being made through the API? 

Tagging @mathio and @picsoung in case they can help, too!

Badge +1

@Liz I am using CHATGPT API to create it, this is the prompt:
 

You are an expert quiz creator specializing in creating multiple-choice questions in a Typeform-compatible JSON format from transcripts. Your task is to analyze the following transcript and generate quiz content, including a name field and precisely 10 challenging multiple-choice questions in English.

Transcript: [Insert your transcript content here]

Guidelines:
- Name Field: Include a "short_text" field with the "ref" value set to "name_field" and mark it as required. This field should be the first item in the JSON array.
- Questions: Create 10 multiple-choice questions, each with a clear and concise "title" and a unique "ref" value (e.g., "question_1", "question_2", etc.). The "ref" values should be in the format "question_[number]" (e.g., "question_1", "question_2", etc.).
- Answer Options: Provide 4 plausible answer options for each question within the "choices" array. Mark the correct answer with "ref": "correct" and the incorrect answers with "ref": "incorrect1", "incorrect2", and "incorrect3". Ensure that the correct answer is not always in the same position and varies randomly.
- Difficulty: Craft questions that require a deep understanding of the transcript's content.

Output Format:
Your entire response must be a valid JSON array containing the specified structure for the name field and each question, without any additional text or explanations.

Example Question Object:
{
  "type": "multiple_choice",
  "title": "What is the most common material used for dental implants?",
  "ref": "question_1",
  "properties": {
    "choices": [
      { "label": "Gold", "ref": "incorrect1" },
      { "label": "Titanium", "ref": "correct" },
      { "label": "Silver", "ref": "incorrect2" },
      { "label": "Ceramic", "ref": "incorrect3" }
    ],
    "randomize": false,
    "allow_other_choice": false
  },
  "validations": {
    "required": true
  }
}

Output exactly 11 objects in the specified JSON format:
1. The name field object
2-11. The 10 question objects

Include only the JSON array in your response.

and this is its output in JSON:

 

 

[

  {

    "type": "short_text",

    "title": "Please enter your name:",

    "ref": "name_field",

    "validations": {

      "required": true

    }

  },

  {

    "type": "multiple_choice",

    "title": "What was the main purpose of the dental implants as defined in the transcript?",

    "ref": "question_1",

    "properties": {

      "choices": [

        {

          "label": "To replace missing teeth and support prosthetic devices",

          "ref": "correct"

        },

        {

          "label": "To enhance the appearance of the gums",

          "ref": "incorrect1"

        },

        {

          "label": "To prevent tooth decay",

          "ref": "incorrect2"

        },

        {

          "label": "To whiten teeth",

          "ref": "incorrect3"

        }

      ],

      "randomize": false,

      "allow_other_choice": false

    },

    "validations": {

      "required": true

    }

  },

  {

    "type": "multiple_choice",

    "title": "Who discovered the beneficial properties of titanium for dental implants?",

    "ref": "question_2",

    "properties": {

      "choices": [

        {

          "label": "Dr. Strauman",

          "ref": "incorrect1"

        },

        {

          "label": "Dr. Brenemak",

          "ref": "correct"

        },

        {

          "label": "Dr. Gadia",

          "ref": "incorrect2"

        },

        {

          "label": "Dr. Moshe",

          "ref": "incorrect3"

        }

      ],

      "randomize": false,

      "allow_other_choice": false

    },

    "validations": {

      "required": true

    }

  },

  {

    "type": "multiple_choice",

    "title": "What is the titanium content range for commercially pure titanium?",

    "ref": "question_3",

    "properties": {

      "choices": [

        {

          "label": "90.5% to 95.5%",

          "ref": "incorrect1"

        },

        {

          "label": "98.5% to 99.5%",

          "ref": "correct"

        },

        {

          "label": "85.5% to 90.5%",

          "ref": "incorrect2"

        },

        {

          "label": "92.5% to 97.5%",

          "ref": "incorrect3"

        }

      ],

      "randomize": false,

      "allow_other_choice": false

    },

    "validations": {

      "required": true

    }

  },

  {

    "type": "multiple_choice",

    "title": "What does RBM stand for in the context of dental implants?",

    "ref": "question_4",

    "properties": {

      "choices": [

        {

          "label": "Resolving Blasting Media",

          "ref": "incorrect1"

        },

        {

          "label": "Resorbable Blasting Media",

          "ref": "correct"

        },

        {

          "label": "Reactive Blasting Material",

          "ref": "incorrect2"

        },

        {

          "label": "Reversible Blasting Mechanism",

          "ref": "incorrect3"

        }

      ],

      "randomize": false,

      "allow_other_choice": false

    },

    "validations": {

      "required": true

    }

  },

  {

    "type": "multiple_choice",

    "title": "What is grade 23 titanium?",

    "ref": "question_5",

    "properties": {

      "choices": [

        {

          "label": "A lower quality titanium alloy",

          "ref": "incorrect1"

        },

        {

          "label": "An improved version of grade 5 titanium",

          "ref": "correct"

        },

        {

          "label": "A cosmetic grade titanium",

          "ref": "incorrect2"

        },

        {

          "label": "An experimental titanium alloy",

          "ref": "incorrect3"

        }

      ],

      "randomize": false,

      "allow_other_choice": false

    },

    "validations": {

      "required": true

    }

  },

  {

    "type": "multiple_choice",

    "title": "What is the purpose of using hydroxyapatite in the RBM process?",

    "ref": "question_6",

    "properties": {

      "choices": [

        {

          "label": "To prevent tooth decay",

          "ref": "incorrect1"

        },

        {

          "label": "To enhance biocompatibility",

          "ref": "correct"

        },

        {

          "label": "To provide a smooth finish",

          "ref": "incorrect2"

        },

        {

          "label": "To add color to the implant",

          "ref": "incorrect3"

        }

      ],

      "randomize": false,

      "allow_other_choice": false

    },

    "validations": {

      "required": true

    }

  },

  {

    "type": "multiple_choice",

    "title": "What is one main disadvantage of the SLA surface treatment?",

    "ref": "question_7",

    "properties": {

      "choices": [

        {

          "label": "It reduces the strength of the titanium",

          "ref": "incorrect1"

        },

        {

          "label": "It leaves contaminant residues",

          "ref": "correct"

        },

        {

          "label": "It makes the implant too smooth",

          "ref": "incorrect2"

        },

        {

          "label": "It increases the cost significantly",

          "ref": "incorrect3"

        }

      ],

      "randomize": false,

      "allow_other_choice": false

    },

    "validations": {

      "required": true

    }

  },

  {

    "type": "multiple_choice",

    "title": "Which type of dental implants are generally used when there is severe atrophic maxilla?",

    "ref": "question_8",

    "properties": {

      "choices": [

        {

          "label": "Bone level implants",

          "ref": "incorrect1"

        },

        {

          "label": "Tissue level implants",

          "ref": "incorrect2"

        },

        {

          "label": "Zygomatic dental implants",

          "ref": "correct"

        },

        {

          "label": "One piece implants",

          "ref": "incorrect3"

        }

      ],

      "randomize": false,

      "allow_other_choice": false

    },

    "validations": {

      "required": true

    }

  },

  {

    "type": "multiple_choice",

    "title": "What is the primary reason for using grade 23 titanium in dental implants?",

    "ref": "question_9",

    "properties": {

      "choices": [

        {

          "label": "It is the cheapest material available",

          "ref": "incorrect1"

        },

        {

          "label": "It is the most flexible material",

          "ref": "incorrect2"

        },

        {

          "label": "It has improved strength and biocompatibility",

          "ref": "correct"

        },

        {

          "label": "It is easier to manufacture",

          "ref": "incorrect3"

        }

      ],

      "randomize": false,

      "allow_other_choice": false

    },

    "validations": {

      "required": true

    }

  },

  {

    "type": "multiple_choice",

    "title": "Which type of implants are placed in the jaw bone and protrude through the gum?",

    "ref": "question_10",

    "properties": {

      "choices": [

        {

          "label": "Subperiosteal implants",

          "ref": "incorrect1"

        },

        {

          "label": "Endosteal implants",

          "ref": "correct"

        },

        {

          "label": "Zygomatic implants",

          "ref": "incorrect2"

        },

        {

          "label": "One piece implants",

          "ref": "incorrect3"

        }

      ],

      "randomize": false,

      "allow_other_choice": false

    },

    "validations": {

      "required": true

    }

  }

]


Do u manage to find something there?


Thank you in advance !!:)

Userlevel 7
Badge +5

Thanks, @Rafa1610 ! @mathio or @picsoung do either of you know if this call is correct? 

Userlevel 7
Badge +5

@Liz  I am sorry, but I cant help with this one ☹️

Badge +1

@mathio  thank you anway…. @Liz any other idea? unfortunately still stuck:(

Badge +1

I moved a step forward, but still unable to send the API request to Typeform.

I will provide a brief recap:

Background:

I am working on a project to create a dynamic quiz using Typeform, with questions generated from a transcript using the ChatGPT API. The goal is to generate multiple-choice questions, track the user's score, and display the final score on the thank you screen. The integration process involves using Zapier to handle the data flow and logic between ChatGPT and Typeform.

Process Overview:

  1. ChatGPT API Prompt: The following prompt is used to instruct ChatGPT to generate the quiz questions:

     
    plaintext

    Copy code

    You are an expert quiz creator specializing in creating multiple-choice questions in a Typeform-compatible JSON format from transcripts. Your task is to analyze the following transcript and generate quiz content, including a name field and precisely 10 challenging multiple-choice questions in English. Transcript: {{240955785__transcript}} Guidelines: - Name Field: Include a "short_text" field with the "ref" value set to "name_field" and mark it as required. This field should be the first item in the JSON array. - Questions: Create 10 multiple-choice questions, each with a clear and concise "title" and a unique "ref" value (e.g., "question_1", "question_2", etc.). The "ref" values should be in the format "question_[number]" (e.g., "question_1", "question_2", etc.). - Answer Options: Provide 4 plausible answer options for each question within the "choices" array. Mark the correct answer with "ref": "correct" and the incorrect answers with "ref": "incorrect1", "incorrect2", and "incorrect3". Ensure that the correct answer is not always in the same position and varies randomly. - Difficulty: Craft questions that require a deep understanding of the transcript's content. Output Format: Output ONLY the valid JSON array containing the specified structure for the name field and each question. Do NOT include any additional text, explanations, or formatting characters. Example Question Object: { "type": "multiple_choice", "title": "What is the most common material used for dental implants?", "ref": "question_1", "properties": { "choices": [ { "label": "Gold", "ref": "incorrect1" }, { "label": "Titanium", "ref": "correct" }, { "label": "Silver", "ref": "incorrect2" }, { "label": "Ceramic", "ref": "incorrect3" } ], "randomize": false, "allow_other_choice": false }, "validations": { "required": true } } Output exactly 10 question objects in the specified JSON format. Include only the JSON array in your response.

  2. Zapier Code: The following code in Zapier processes the ChatGPT output, generates the Typeform fields, and creates scoring logic for tracking the user's score:

     
    javascript

    Copy code

    const chatGPToutput = inputData['Conversation in ChatGPT']; let typeformFields = []; let scoringLogic = []; try { typeformFields = JSON.parse(chatGPToutput); // Extract question references (excluding the name field) const questionRefs = typeformFields .filter(field => field.type === 'multiple_choice') .map(field => field.ref); // Generate scoring logic for each question scoringLogic = questionRefs.map(ref => ({ type: 'field', ref: ref, actions: [ { action: 'add', details: { target: { type: 'variable', value: 'score' }, value: { type: 'constant', value: 1 } }, condition: { op: 'is', vars: [ { type: 'field', value: ref }, { type: 'choice', value: typeformFields.find(field => field.ref === ref).properties.choices.find(choice => choice.ref === 'correct').ref } ] } } ] })); } catch (error) { console.error("Error parsing JSON from ChatGPT:", error); } return { typeformFields: JSON.stringify(typeformFields), scoringLogic: JSON.stringify(scoringLogic), scoreVariable: '{{score}}' };

  3. Typeform API Request: The API request in Typeform uses the fields and logic generated by the Zapier code to create the quiz and attempts to display the final score on the thank you screen:

     
    json

    Copy code

    { "title": "Quiz from Transcript", "variables": { "score": 0 }, "theme": { "href": "https://api.typeform.com/themes/dBADdiNW" }, "fields": {{241267617__typeformFields}}, "logic": {{241267617__scoringLogic}}, "thankyou_screens": [ { "title": "Thank you!\nYour Final Score is\n{{241267617__scoreVariable}}", "properties": { "show_button": true, "button_text": "Create a typeform", "button_mode": "default_redirect", "share_icons": true } } ] }

Problem:

  • The score variable does not transfer the data correctly from the previous steps into the API request in Typeform.
  • Despite setting up the scoring logic, the final score is not displayed correctly on the thank you screen.

Challenge:

  • Ensure the score variable correctly passes the data from Zapier to Typeform and displays it accurately.
  • Explore alternative methods to recall the score and display it on the thank you screen.

Final Goal:

  • Successfully display the user's final score on the thank you screen after completing the quiz.

Request for Help:

  • I need guidance on debugging this issue and finding a solution to correctly display the score using the current setup.
  • Any insights or suggestions on how to improve the data transfer between Zapier and Typeform or alternative methods to achieve the desired result would be greatly appreciated.

Reply