CloudCherry is now part of Cisco.
Learn More About Cisco

Real-time survey Creation

Understanding various use cases for creating survey tokens real-time

Businesses have various internal systems that houses data. Systems such as CRM systems, Helpdesk tools, POS systems, Marketing automation tools, Loyalty program management tools etc are in play in every organization. Reaching out to customers with a survey as soon as a transaction is completed by them yields the highest response rates. Integrations with CloudCherry survey creation APIs can be built easily.

Let's pick a couple of use cases to explain the scenario.

Use case 1:

CRM systems such as Salesforce or Microsoft Dynamics has case management (ticketing) capabilities. Even helpdesk tools such as Freshdesk or Zendesk are pretty popular for ticketing. Let’s consider a scenario where the business wants to reach out to their customers for a post ticket closure surveys to measure the agent satisfaction metric as soon as a ticket is closed.

The following steps are to be followed to build this simple integration using the open API's provided by CloudCherry.

Store the Access Token received from Authentication API and use it for next 24hours to create survey links dynamically. Pass the required prefill information while creating token

Please click here to see how you can prefill data using API.

Helpdesk tools such as Freshdesk, Zendesk etc doesn’t have workflows that will send emails to end customers. In such cases, email delivery will also have to be programmatically accommodated. Please refer to the last step of Use case 2 to understand how this can be done.

using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Net.Http; using System.Text; using System.Threading.Tasks;

C# Survey Token Creation Code

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace TokenCreation
{
    public class SingleTokenCreation
    {
        public async Task<string> CreateSingleToken(string accessToken)
        {
            //Base URL
            string endPoint = "https://api.getcloudcherry.com";
            //URL to Create Token
            string url = endPoint + "/api/surveytoken";
            //Adding Prefills
            var prefills = new List<Dictionary<string, object>>()
            {
                // Values mentioned below are Dummy
                // Adding Prefills
                // Should include all the prefiils required to be filled dynamically
                new Dictionary<string,object>()
                {
                    { "numberInput" , 0 },
                    {  "questionId" , "5bec23dc4145b1295063328c" },
                    { "questionText" , "Please enter your name" },
                    { "textInput" , "Dummy Name" }
                }
            };
            //Composing Body 
            var param = new Dictionary<string, object>
            {
                { "validTill", "2014-10-31T18:30:00.000Z" }, // Provide the Survey Expiry Time in UTC format
                { "validUses", "1" },  // Number of times the survey can be submitted
                { "location", "Account Opening-Dummy" }, // Provide the CC questionnaire name
                { "note", "Created by XYZ integration team" }, // Information about the survey creation. Not Mandatory.
                { "preFill", prefills } 
            };
            string jsonBody = JsonConvert.SerializeObject(param);
            HttpRequestMessage request;
            HttpResponseMessage response;
            var httpClient = new HttpClient();
            try
            {
                request = new HttpRequestMessage(HttpMethod.Post, url);
                request.Content = new StringContent(jsonBody, Encoding.UTF8, "application/json");
                // Access Token retrieved from LoginAPI should be passed here
                request.Headers.Add("Authorization", "Bearer " + accessToken);
                response = await httpClient.SendAsync(request);
                string responseBodyAsText = string.Empty;
                // Check for the valid response
                if (response != null && response.IsSuccessStatusCode)
                {
                    responseBodyAsText = await response.Content.ReadAsStringAsync();
                    var responseJson = JsonConvert.DeserializeObject<Dictionary<string, object>>(responseBodyAsText);
                    responseJson.TryGetValue("id", out object token); // Look for Token
                    // Survey URL format should be
                    // Survey URL = "https://nps.bz/" + token
                    return token?.ToString();
                }
                return responseBodyAsText;
            }
            catch (Exception)
            {
                return null;
            }
        }
    }
}

Use case 2:

POS systems records all the sales that happens in a store. Let’s consider a retail business that has multiple stores and uses a POS system to record sales. After each sale, an email or SMS has to be sent to the customer with a survey link in it to measure post transaction NPS.

Please follow the below steps to implement this integration:

Store the Access Token received from Authentication API and use it for next 24hours to create survey links dynamically. Pass the required prefill information while creating token

Please use the below sample code to integrate the Requestinvitation API.

Create Survey Token: POST /api/RequestInvitation

* Configure custom SMTP details under the Integration section of the CloudCherry Insight center
* For SMS, please use the parameter names “Template”
* Please refer to the comments in the sample code to know more about each parameter in the API call

C# Request Invitation Code

   
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;


namespace TokenCreation
{
    public class SingleTokenWithInvite
    {
        public async Task<string> SendInvite(string accessToken)
        {
            //Base URL
            string endPoint = "https://api.getcloudcherry.com";
            //URL to Create Token
            string url = endPoint + "/api/RequestInvitation";
            //Adding Prefills.
            var prefills = new List<Dictionary<string, object>>()
            {
                // Values mentioned below are Dummy
                // Adding Prefills
                // Should include all the prefiils required to be filled dynamically
                new Dictionary<string,object>()
                {
                    { "numberInput" , 0 },
                    {  "questionId" , "5bec23dc4145b1295063328c" },
                    { "questionText" , "Please enter your name" },
                    { "textInput" , "Harish" }
                }
            };
            //Composing Request Body 
            var tokenDetails = new Dictionary<string, object>
            {
                { "note", "Email After Service Interaction #23456" }, // Information about the survey creation. Not Mandatory.
                { "preFill", prefills }, 
                { "user", "ccusername" }, // Provide your CloudCherry user name
                { "location" ,"Branch" }, // Provide the CC questionnaire name
                { "validTill", "2019-09-20T07:32:11.912Z" }, // Provide the Survey Expiry Time in UTC format
                { "validUses", 1 } // Number of times the survey can be submitted
            };
            var prefillQuestiontag = new Dictionary<string, string>()
            {
                { "cc_touchpoint" , "Branch" } // Provide the CC questionnaire name
            };
            // Provide your dispatch details to be used for sending invite
            var param = new Dictionary<string, object>()
            {
                { "tokenDetails", tokenDetails },
                { "preFillByQuestionTag", prefillQuestiontag },
                { "customerEmail", "harishkanth@hotmail.com" }, // Customer Email ID
                { "customerName" , "Harish" }, // Customer Name
                { "subject" , "We need your feedback" }, //Email Subject
                { "template" , "TemplateID" }, //If Email, get templateID from product. If SMS, provide custom
                                               // SMS body with authentical detail in same URL
                { "customerPhone", "919940221973" }, // Only required, when SMS to be sent
                { "isSMS",false }, // True for sending SMS, false for sending Email
            };
            string jsonBody = JsonConvert.SerializeObject(param);
            HttpRequestMessage request;
            HttpResponseMessage response;
            var httpClient = new HttpClient();
            try
            {
                request = new HttpRequestMessage(HttpMethod.Post, url);
                request.Content = new StringContent(jsonBody, Encoding.UTF8, "application/json");
                // Access Token retrieved from LoginAPI should be passed here
                request.Headers.Add("Authorization", "Bearer " + accessToken);
                response = await httpClient.SendAsync(request);
                string responseBodyAsText = string.Empty;
                // Check for the valid response
                if (response != null && response.IsSuccessStatusCode)
                {
                    responseBodyAsText = await response.Content.ReadAsStringAsync();
                    var responseJson = JsonConvert.DeserializeObject<Dictionary<string, object>>(responseBodyAsText);
                    responseJson.TryGetValue("message", out object message);
                    return message?.ToString();
                }
                return responseBodyAsText;
            }
            catch (Exception)
            {
                return null;
            }
        }
    }
}