CloudCherry is now part of Cisco.
Learn More About Cisco

Java

Hello World using Java

Download Webex Experience Management Java API Client Jar / Source for usage in your Java Project.

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Map.Entry;

import cloudcherry.*;
import cloudcherry.APIClient.AnalyticsSummary;
import cloudcherry.APIClient.Answer;
import cloudcherry.APIClient.FilterBy;
import cloudcherry.APIClient.NPS;
import cloudcherry.APIClient.Notification;
import cloudcherry.APIClient.Question;
import cloudcherry.APIClient.Response;
import cloudcherry.APIClient.ResponseSummary;
import cloudcherry.APIClient.SSOSubUser;
import cloudcherry.APIClient.SummaryLite;
import cloudcherry.APIClient.SurveyToken;
import cloudcherry.APIClient.TokenSurvey;
import cloudcherry.APIClient.UserSettings;

public class HelloWebex Experience ManagementAPI {
  public static APIClient apiclient;
  public static List < Question > questions;
  public static UserSettings settings;
  public static List < Answer > Answers;
  public static FilterBy filter;
  private final static String apiEndPoint = "https://api.getcloudcherry.com";
  public static String username = "";
  public static String password = "";
  static Calendar c;

  public static void main(String[] args) throws Exception {

    String account = "yourusername";
    String ssokey = "yourpassword";

    @SuppressWarnings("resource")
    Scanner user_input = new Scanner(System. in );
    apiclient = new APIClient(apiEndPoint, "", "");
    Date Now = new Date();
    c = Calendar.getInstance();
    c.setTime(Now);
    c.add(Calendar.DATE, -30);
    Date after = c.getTime();
    filter = apiclient.new FilterBy();
    filter.beforedate = Now;
    filter.afterdate = after;
    filter.beforetime = new Date();
    filter.afterdate = c.getTime();
    boolean exit = false;
    boolean ISLoggedIn = false;
    while (!exit) {
      if (!ISLoggedIn) {
        System.out.println("");
        System.out.print("Enter your user name: ");
        username = user_input.next(); //Get Username
        System.out.print("Enter your password: ");
        password = user_input.next(); //Get Password
        apiclient = new APIClient(apiEndPoint, username, password);
        ISLoggedIn = apiclient.Login();
      }
      if (ISLoggedIn) {



        String optionValue = "";

        // Display menu graphics
        System.out.println("======================================");
        System.out.println("|   MENU SELECTION                    |");
        System.out.println("======================================");
        System.out.println("| Options:                            |");
        System.out.println("|        1. Get Questions             |");
        System.out.println("|        2. Add Questions             |");
        System.out.println("|        3. Delete Questions          |");
        System.out.println("|        4. Update Questions          |");
        System.out.println("|        5. Get Settings              |");
        System.out.println("|        6. Update Settings           |");
        System.out.println("|        7. Get Answers               |");
        System.out.println("|        8. Post Answer               |");
        System.out.println("|        9. Get Summary               |");
        System.out.println("|       10. Get Analytics By Location |");
        System.out.println("|       11. Get IntersectQuestions    |");
        System.out.println("|       12. Set Filter                |");
        System.out.println("|       13. Get SurveyTokens          |");
        System.out.println("|       14. Get TokenSurvey           |");
        System.out.println("|       15. Add SurveyToken           |");
        System.out.println("|       16. Delete SurveyToken        |");
        System.out.println("|       17. Update SurveyToken        |");
        System.out.println("|       18. Post SurveyBy Token       |");
        System.out.println("|       19. Check API Status          |");
        System.out.println("|       20. DownloadContent           |");
        System.out.println("|       21. Generate SSOUrl           |");
        System.out.println("|       22. Get QRToken               |");
        System.out.println("|       23. Logout (Exit)             |");
        System.out.println("======================================");
        System.out.println("Enter Your Choice: ");
        optionValue = user_input.next();

        switch (optionValue) {
          case "1":
            System.out.println("Get Questions selected");
            List < Question > questions = apiclient.GetQuestions(false);
            if (questions != null) {
              for (Question question: questions) {
                System.out.println("Questions: " + question.ToString());
              }
            }
            break;
          case "2":
            System.out.println("Add Questions selected");
            Question question = apiclient.new Question();
            question.sequence = 2;
            System.out.println("Enter Question Text");
            question.text = user_input.next();
            question.userWeight = 8.0;
            question.goodAfter = new Date();
            Calendar c = new GregorianCalendar();
            c.add(Calendar.DATE, 30);
            Date d = c.getTime();
            question.goodBefore = d;
            question.timeOfDayAfter = new Date();
            question.timeOfDayBefore = new Date();
            question.displayType = "Select";
            question.multiSelect = new ArrayList < String > ();
            question.multiSelect.add("Yeah;yes.png");
            question.multiSelect.add("Nope;No.png");
            question.displayLocation = new ArrayList < String > ();
            question.displayLocation.add("NSK");
            Question addedquestion = apiclient.AddQuestion(question);
            if (addedquestion != null) {
              System.out.println("Added Question: " + addedquestion.ToString());
            }
            break;
          case "3":
            System.out.println("Delete Questions selected");
            System.out.println("Enter Question ID");
            String id = user_input.next();
            Boolean ISdeleted = apiclient.DeleteQuestion(id);
            if (ISdeleted) System.out.println("Deleted");
            else System.out.println("Not Deleted");
            break;
          case "4":
            System.out.println("Update Questions selected");
            Question updatequestion = apiclient.new Question();
            System.out.println("Enter Question ID to update");
            updatequestion.id = user_input.next();
            updatequestion.sequence = 2;
            updatequestion.text = "Updated Question";
            updatequestion.userWeight = 7.0;
            updatequestion.goodAfter = new Date();
            updatequestion.displayType = "MultiSelect";
            updatequestion.multiSelect = new ArrayList < String > ();
            updatequestion.multiSelect.add("Yeah");
            updatequestion.multiSelect.add("Noˆ");
            updatequestion.displayLocation = new ArrayList < String > ();
            updatequestion.displayLocation.add("KSN");
            Question updatedQuestion = apiclient.UpdateQuestion(updatequestion);
            if (updatedQuestion != null) {
              System.out.println("Added Question: " + updatedQuestion.ToString());
            }
            break;
          case "5":
            System.out.println("Get Settings selected");
            settings = apiclient.GetSettings();
            if (settings != null) {
              System.out.println("Settings: " + settings);
            }
            break;
          case "6":
            System.out.println("Update Settings selected");
            if (settings != null) {
              settings.businessType = "Profitable Brand";
              Notification not = apiclient.new Notification();
              not.email = "cc@gmail.com";
              settings.notifications.add(not);
              UserSettings updatedsettings = apiclient.UpdateSettings(settings);
              if (updatedsettings != null) System.out.println("Updated");
              else System.out.println("Not Updated");
            } else System.out.println("Get Your Settings First");
            break;
          case "7":
            System.out.println("Get Answers selected");
            Answers = apiclient.GetAnswers(filter);
            if (Answers != null) {
              int Rindex = 1;
              for (Answer a: Answers) {
                System.out.println("");
                System.out.println("(" + Rindex + ") " + "Response: " + a.locationId + " " + a.responseDateTime);
                System.out.println("-----------------------------------------------");
                System.out.println("");
                if (a.responses != null) {
                  for (Response r: a.responses) {
                    if (r.textInput == null || r.textInput.isEmpty()) System.out.println(r.questionText + ": " + Integer.toString(r.numberInput));
                    else System.out.println(r.questionText + ": " + r.textInput);
                  }
                }
                Rindex++;
              }
            }
            break;
          case "8":
            System.out.println("Post Answer selected");
            Answer postanswer = apiclient.new Answer();
            postanswer.responseDateTime = new Date();
            //postanswer.locationId = "NSK";
            postanswer.responses = new ArrayList < Response > ();
            Response res = apiclient.new Response();
            System.out.println("Enter Question Id");
            String QID = user_input.next().trim();
            System.out.println("Enter Text");
            String Qtext = user_input.next().trim();
            res.questionId = QID;
            res.questionText = Qtext;
            res.textInput = "Post Text";
            postanswer.responses.add(res);
            Answer posted = apiclient.PostAnswer(postanswer);
            if (posted != null) {
              System.out.println(posted.id + " Response Time: " + posted.responseDateTime);
            }
            break;
          case "9":
            System.out.println("Get Summary selected");
            ResponseSummary summary = apiclient.GetSummary(filter);
            if (summary != null) {
              System.out.println("Response Count: " + summary.responseCount);
              System.out.println("Delight Score: " + summary.weightedScore);
            }
            break;
          case "10":
            System.out.println("Get Analytics By Location selected");
            Map < String, AnalyticsSummary > Locationsummary = apiclient.GetAnalyticsByLocation(filter);
            if (Locationsummary != null) {
              for (Entry < String, AnalyticsSummary > entry: Locationsummary.entrySet()) {
                System.out.println(entry.getKey());
                AnalyticsSummary analyticssummary = entry.getValue();
                if (analyticssummary != null) {
                  System.out.println("Location " + analyticssummary.locationName);
                  System.out.println("-----------------------------------------------");
                  if (analyticssummary.perDayResponseCount != null) System.out.println("perDayResponseCount " + analyticssummary.perDayResponseCount.size());
                  System.out.println("MDM " + analyticssummary.mdm);
                  System.out.println("CDMToken " + analyticssummary.cdmToken);
                  System.out.println("Total Responses " + analyticssummary.totalResponses);
                  System.out.println("Liked " + analyticssummary.liked);
                  System.out.println("Disliked " + analyticssummary.disliked);
                  NPS nps = analyticssummary.netPromoter;
                  if (nps != null) {
                    System.out.println("Net Promoters " + nps.netPromoters);
                  }
                  System.out.println("");
                }
              }
            }
            break;
          case "11":
            System.out.println("Get IntersectQuestions selected");
            String questionid1 = "";
            String questionid2 = "";
            System.out.println("Enter Question1's ID to compare");
            questionid1 = user_input.next().trim();
            System.out.println("Enter Question2's ID to compare");
            questionid2 = user_input.next().trim();
            Map < String, SummaryLite > intersectquestions = apiclient.IntersectQuestions(filter, questionid1, questionid2);
            if (intersectquestions != null) {
              for (Entry < String, SummaryLite > entry: intersectquestions.entrySet()) {
                System.out.println(entry.getKey());
                SummaryLite summarylite = entry.getValue();
                System.out.println("Asked Question " + summarylite.askedQuestion);
                for (Entry < String, Integer > responseEntry: summarylite.response.entrySet()) {
                  System.out.println("Values: ");
                  System.out.println(responseEntry.getKey() + "/" + responseEntry.getValue());
                }
              }
            }
            break;
          case "12":
            System.out.println("Set Filter (90 days) Selected");
            Now = new Date();
            c = Calendar.getInstance();
            c.setTime(Now);
            c.add(Calendar.DATE, -90);
            after = c.getTime();
            filter = apiclient.new FilterBy();
            filter.afterdate = after;
            filter.beforedate = Now;
            break;
          case "13":
            System.out.println("Get SurveyTokens selected");
            List < SurveyToken > surveytokens = apiclient.GetSurveyTokens();
            if (surveytokens != null) {
              for (SurveyToken surveyToken: surveytokens) {
                System.out.println("");
                System.out.println("SurveyToken ID: " + surveyToken.id);
                System.out.println("SurveyToken Location: " + surveyToken.location);
                System.out.println("SurveyToken emailQuestion: " + surveyToken.emailQuestion);
                System.out.println("SurveyToken validTill: " + surveyToken.validTill);
                System.out.println("SurveyToken validUses: " + surveyToken.validUses);
                System.out.println("");
              }
            }
            break;
          case "14":
            System.out.println("Get TokenSurvey selected");
            System.out.println("EnterToken");
            String Stringtoken = user_input.next().trim();
            TokenSurvey token = apiclient.GetTokenSurvey(Stringtoken);
            if (token != null) {
              System.out.println("");
              System.out.println("Welcome Text: " + token.welcomeText);
              System.out.println("Thankyou Text: " + token.thankyouText);
              System.out.println("");
            }
            break;
          case "15":
            System.out.println("Add SurveyToken selected");
            SurveyToken Tobeadded = apiclient.new SurveyToken();
            Tobeadded.validTill = new Date();
            Tobeadded.validUses = 10;
            SurveyToken Addsurveytoken = apiclient.AddSurveyToken(Tobeadded);
            if (Addsurveytoken != null) {
              System.out.println("SurveyToken ID: " + Addsurveytoken.id);
              System.out.println("SurveyToken validTill: " + Addsurveytoken.validTill);
              System.out.println("SurveyToken validUses: " + Addsurveytoken.validUses);
            }
            break;
          case "16":
            System.out.println("Delete SurveyToken selected");
            String TokenId = "";
            System.out.println("Enter Token Id to delete");
            TokenId = user_input.next().trim();
            boolean isdeleted = apiclient.DeleteSurveyToken(TokenId);
            if (isdeleted) System.out.println("Deleted :" + TokenId);
            else System.out.println("Unable to delete");
            break;
          case "17":
            System.out.println("Update SurveyToken selected");
            SurveyToken Tobeupdated = apiclient.new SurveyToken();
            System.out.println("Enter Token Id to update");
            String UpdateTokenId = user_input.next().trim();
            Tobeupdated.id = UpdateTokenId;
            Tobeupdated.validTill = new Date();
            Tobeupdated.validUses = 10;
            SurveyToken updatedsurveytoken = apiclient.UpdateSurveyToken(Tobeupdated);
            if (updatedsurveytoken != null) {
              System.out.println("SurveyToken ID: " + updatedsurveytoken.id);
              System.out.println("SurveyToken validTill: " + updatedsurveytoken.validTill);
              System.out.println("SurveyToken validUses: " + updatedsurveytoken.validUses);
            }
            break;
          case "18":
            System.out.println("Post SurveyBy Token selected");
            System.out.println("Enter Token Id to Post");
            String PostTokenId = user_input.next().trim();
            Answer a = apiclient.new Answer();
            a.responseDateTime = new Date();
            //a.locationId = "NSK";
            a.responses = new ArrayList < Response > ();
            System.out.println("Enter Question Id");
            String QIDtoken = user_input.next().trim();
            System.out.println("Enter Question Text");
            String Qtexttoken = user_input.next().trim();
            Response r = apiclient.new Response();
            r.questionId = QIDtoken;
            r.questionText = Qtexttoken;
            r.textInput = "Text";
            a.responses.add(r);
            Answer PostedResponse = apiclient.PostSurveyByTokenResponse(PostTokenId, a);
            if (PostedResponse != null) {
              System.out.println(PostedResponse.id + " Response Time: " + PostedResponse.responseDateTime);
            }
            break;
          case "19":
            System.out.println("Check API Status selected");
            boolean check = apiclient.CheckAPIStatus();
            System.out.println("API Alive?? : " + check);
            break;
          case "20":
            System.out.println("DownloadContent selected");
            byte[] Download = apiclient.DownloadContent("https://az592622.vo.msecnd.net/assets/extremelyhappy.png");
            if (Download != null) System.out.println("Downloaded Size : " + Download.length);
            break;
          case "21":
            SSOSubUser subuser = new APIClient.SSOSubUser();
            System.out.println("Enter Userid");
            subuser.userid = user_input.next().trim();
            System.out.println("Enter Role");
            subuser.role = user_input.next().trim();
            System.out.println("Enter Email");
            subuser.email = user_input.next().trim();
            subuser.timeStamp = new Date();
            System.out.println("Enter SSOKey");
            String SSOKey = user_input.next().trim();
            String SSOUrl = APIClient.GenerateSSOUrl(subuser,username,SSOKey);
            if(SSOUrl != null && !SSOUrl.equals(""))
               System.out.println("SSOUrl : " +SSOUrl);
            else
              System.out.println("Error");
            break;
          case "22":
            System.out.println("Enter Your Token");
            String QRtoken = user_input.next().trim();
            byte[] QRImage = apiclient.DownloadQRToken(QRtoken);
            if(QRImage != null) System.out.println("Downloaded Size : "+QRImage.length);
            break;
          case "23":
            System.out.println("Logout selected");
            boolean ISlogout = apiclient.Logout();
            ISLoggedIn = false;
            username = "";
            password = "";
            System.out.println("Logged Out?? : " + ISlogout);
            System.out.print("Press 'Y' to continue : ");
            String iscontinue = user_input.next();
            if (iscontinue.equalsIgnoreCase("Y")) exit = false;
            else exit = true;
            break;
          default:
            System.out.println("Invalid selection");
            break;
        }
        if (!exit && ISLoggedIn) {
          System.out.print("Press Any Key to continue : ");
          user_input.next();
        }
      } else {
        System.out.println("Error" + apiclient.errorLogin);
        System.out.print("Press 'Y' to continue : ");
        String iscontinue = user_input.next();
        if (iscontinue.equalsIgnoreCase("Y")) exit = false;
        else exit = true;
      }
    }
  }
}