Quiz webhook – send data and leads to any software

3 min read

We built Riddle to easily connect with any marketing software or CRM tool. Our new quiz webhook joins our existing range of data connection options, from using Zapier to native integrations with AWeber and MailChimp (with more coming!).

The use cases are endless. You can auto segment leads based on their responses, automatically send data to your marketing software for instant email follow ups, and a million more.

Using our webhook does require programming skills. You need to know how to work with arrays and need to have a good understanding of PHP to receive and process the webhook data. If you are not the type that loves to dig into code, you can always use our free zapier.com app to process Riddle data and send it on to a tool of your choice. In many cases, that is the easier way to process Riddle data.

Quiz webhook: the essentials

Now we are going to get your inner geek going at full speed and show you how to write your own quiz webhook with just a few lines of PHP.

To get started, it would be good if you have:

  • a good understanding of PHP
  • a bit of knowledge about JSON
  • your own server or a cool place where you can upload a PHP file that is reachable on the web
  • a Riddle Pro or Enterprise account or a free 14 day trial account with all features unlocked

Quiz webhook: getting started

  1. Right, first off – create any Riddle quiz, poll, or other content.
  2. Include a lead gen form using Riddle’s lead form builder.
  3. Go to the ‘Advanced’ step in the quiz editor.
  4. Here you paste the URL of the page where your personal webhook code will run. (Something like: http://mydomain.com/riddle_is_awesome.php
  5. Save and publish the Riddle and run through it one time, filling out the form to make sure it all works.
  6. Then create a php file with this tiny bit of code:

Note: for the code below to work, you need to format the Riddle webhook as JSON like this:

webhook formatting as JSON

Here is a sample output in the request.log file generated by the code above:

2019-01-21 13:52:05 Array ( => {“riddleId”:179590,”data”:{“riddle”:{“id”:179590,”title”:”webhook decode json”,”type”:”quiz”}, “lead2”:{“Name”:{“value”:”Sample Name”,”type”:”text”},”Email”:{“value”:”sample@email.com”,”type”:”email”}}, “answers”:[{“question”:”my question</p>”,”answer”:”my answer 1″,”correct”:true,”questionId”:1,”answerId”:1}],
“result”:1,”resultData”:{“scoreNumber”:1,”resultIndex”:1,”scorePercentage”:100,”scoreText”:”Your score: 1/1″,”title”:”good resultn”,

Note that we added a date entry as we are constantly appending data to the same file. 

Next you would need to create code that goes through the JSON array and processes the data any way you like.

You can also use a JSON decoder like JSON Formatter to view the data in a nice and pretty format like this:

         "title":"webhook decode json",
            "value":"Sample Name",
            "question":"my question</p>",
            "answer":"my answer 1",
         "scoreText":"Your score: 1/1",
         "title":"good resultn",

As you can see in the image above, Riddle’s quiz webhook sends you all data as a nicely formatted JSON string via POST.

All you need to do is grab that POST JSON and process it as you like.

Pro Tip: Want to see what quiz data is sent via our quiz webhook?

You can create a webhook and view the results using: https://webhook.site

We used it to generate this code for this sample quiz about San Francisco: https://www.riddle.com/showcase/173491/quiz

Webhook data:

{“riddle”:{“id”:”173491″,”title”:” San Francisco: The Locals’ Challenge”,”type”:”quiz”},”lead2″:{“Name”:{“type”:”text”},”Email”:{“type”:”email”},”#222388: Short text”:{“type”:”text”},”#553264: Dropdown”:{“type”:”select”},”#571749: Newsletter_agree”:{“type”:”checkbox”},”#759039: Date picker”:{“value”:”2018-11-25T18:28:30.373Z”,”type”:”datepicker”},”#1037919: Form intro”:{“value”:”Sign up to win two free tickets to visit San Francisco! :airplane::city_sunrise::beach_with_umbrella:“,”type”:”intro”},”undefined”:{“type”:””}},”answers”:[{“question”:”What’s the easiest way to annoy the locals?”,”answer”:”Calling San Francisco… ‘Frisco'”,”correct”:”1″,”questionId”:”0″,”answerId”:”2″},{“question”:”What’s the dress code for a big night out?”,”answer”:”A “I Love SF” hoodie”,”correct”:”0″,”questionId”:”1″,”answerId”:”3″},{“question”:”Where’s the roughest part of town?”,”answer”:”The Tenderloin”,”correct”:”1″,”questionId”:”2″,”answerId”:”1″},{“question”:”Where you can most often find the ‘Tamale Lady’ for an awesome late night bite?”,”answer”:”Zeitgeist (in the Mission)”,”correct”:”1″,”questionId”:”3″,”answerId”:”2″},{“question”:”What’s the nickname for the fans of the local football team?”,”answer”:”The Fog Bank”,”correct”:”0″,”questionId”:”4″,”answerId”:”1″},{“question”:”What tourist attraction will locals only visit under duress?”,”answer”:”Ferry Building”,”correct”:”1″,”questionId”:”5″,”answerId”:”0″},{“question”:”Best local race?”,”answer”:”Mission to Market Street fun run”,”correct”:”0″,”questionId”:”8″,”answerId”:”1″},{“question”:”What color should you never, ever wear to a Giants game?”,”answer”:”Oakland A’s green”,”correct”:”0″,”questionId”:”7″,”answerId”:”1″}],”result”:”4″,”resultData”:{“scoreNumber”:”4″,”resultIndex”:”4″,”scorePercentage”:”50″,”scoreText”:”Your score: 4/8″,”title”:”You’re from the ‘burbs”,”description”:”Hey there – you’re definitely no tourist, and have even been to SF enough to know your way around. But we can tell you don’t live in the city, and can stand to brush up on a few things. Only one thing to do – pick up sticks and move to our little pocket of paradise!”,”resultId”:”1″},”embed”:{“parentLocation”:”https://www.riddle.com/showcase/173491/quiz”}}

Quiz webhook: wrapping things up

The sky is the limit of where you can go from here. You can write your own code to:

  • push the Riddle data to a CRM of your choice
  • write it all into your own database
  • build your own personal Riddle dashboard
  • and dozens of other use cases

Need help or custom code? Reach out to us via hello@riddle.com and we’re happy to help. Basic questions are easy and free – but we’re also available for hire to write your own webhook if you don’t have the code background).

The code above is just a starting point. Use this improved PHP code to process the data sent through to your hook if you know your way around PHP (as you will see below, this code is just a starting point. It does not really do anything with the data yet)

Don’t know where to start?

Get your hands on ready made code

Check out our Github repository for cool sample scripts. Also please head over to our online documentation to read more about our webhook

Download our free e-book “Quizmaster”

Learn how to use quizzes for your marketing -
capture more leads and grow your business!
Scroll to Top