/
Retrieving Data - Pure Java Script Example - Limited features

Retrieving Data - Pure Java Script Example - Limited features

The example below is a Pure JavaScript and is best used on the client side. For instance this script sits on the Client side platform such as Confirmit/decrypt etc..

It is used when the respondent is redirected back to the client platform after completion of the Virtual Shelf exercise. This example below requests the respondent Data. i.e. what they clicked on and outputs this for the client to implement/map to the field required.

You can see a live example of this in the below link:

Run this Example in JSfiddle.net

 

/* © 2018 ConceptSauce ltd */ /* The API URL and the Respondent ID */ var mappleUrl = "https://survey-api.conceptsauce.io/?projectid=d9a9f217-0c9a-498e-b461-e96976a92f36&pageid=a6ea1ece-5273-4431-bff5-b92937d83642&respondentid=ABSTEST1", submitButton = document.getElementById("btn_continue"); function onSuccess(result) { var questions = result.questions, ul = document.getElementsByTagName("ul"); questions.forEach(function(question) { if (question.questionTitle === "q2") { var products = question.qResponseData.basketContent; productsBoughtFill(ul, products); var clicked = question.qResponseData.productViewEvents; productsClickFill(ul, clicked); } }); submitButton.style.visibility = "visible"; } function onError(response) { alert("Error"); } function productsBoughtFill(ul, products) { var myCount = 0; if (products.length) { ul[0].innerHTML += "<strong>BOUGHT:</strong>"; products.forEach(function(product, id) { ul[0].innerHTML += "<li>UPC: " + product.userMeta.UPC + "</br>TITLE: " + product.title + "</br>QTY: " + product.quantity + "</br>Price: " + product.priceParams.basePrice + "</li>" }); } } function productsClickFill(ul, products) { if (products) { var clickedString = ""; ul[0].innerHTML += "<strong>CLICKED:</strong>"; products.forEach(function(product, id) { ul[0].innerHTML += "<li>UPC: " + product.userMeta.UPC + "</br>TITLE: " + product.title + "</li>"; }); } } function getJSON(url, success, error) { var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'json'; xhr.onload = function() { var status = xhr.status; if (status === 200) { success(xhr.response); } else { error(xhr.response); } }; xhr.send(); }; getJSON(mappleUrl, onSuccess, onError);

 

Related content

API for Respondent Data
API for Respondent Data
More like this
Integration and Redirect Setup
Integration and Redirect Setup
Read with this
Qualtrics API Integration guide + Example Surveys
Qualtrics API Integration guide + Example Surveys
More like this
Decipher Code example
Decipher Code example
Read with this
Confirmit API Integration guide
Confirmit API Integration guide
More like this
Retrieving Data from the API using Syrup.JS
Retrieving Data from the API using Syrup.JS
Read with this

©2020 ConceptSauce ltd / For further help please contact us directly on Team@conceptsauce.io