> ## Documentation Index
> Fetch the complete documentation index at: https://plivo.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Conduct SMS Surveys

> Conduct interactive SMS surveys to collect customer feedback

## Overview

This guide shows how to conduct an SMS survey. Surveys can help businesses with market research. Using SMS for surveys lets organizations process input quickly and efficiently.

You can conduct SMS surveys either by using our PHLO visual workflow builder or our APIs. Follow the instructions in one of the tabs below.

<Tabs>
  <Tab title="Using API">
    Here’s how to use Plivo APIs to create surveys using SMS text messages — sending questions and collecting answers.

    <h2 id="api-{{'Outline' | slugify}}">How it works</h2>

    <Frame>
      <img src="https://mintcdn.com/plivo/sqGJ0ONkT5kTuesy/images/sms-survey.jpg?fit=max&auto=format&n=sqGJ0ONkT5kTuesy&q=85&s=dad94a5f6c2d13b7d92ed8e34c11af4e" alt="Outbound-SMS Flow" width="1446" height="774" data-path="images/sms-survey.jpg" />
    </Frame>

    <h2 id="api-prerequisites">Prerequisites</h2>

    To get started, you need a Plivo account —  [sign up](https://cx.plivo.com/signup) with your work email address if you don’t have one already. To receive incoming messages, you must have a Plivo phone number that supports SMS; you can rent numbers from the [Numbers](https://cx.plivo.com/phone-numbers) page of the Plivo console or by using the [Numbers API](/docs/numbers/). If this is your first time using Plivo APIs, follow our instructions to set up a Java development environment.

    <h2 id="api-{{'Create the survey application' | slugify}}">Create the survey application</h2>

    Edit the PlivoSmsApplication.java file in the src/main/java/com.example.demo/ folder and paste into it this code.

    ```java theme={null}
    package com.example.demo;

    import com.plivo.api.Plivo;
    import com.plivo.api.exceptions.PlivoRestException;
    import com.plivo.api.exceptions.PlivoXmlException;
    import com.plivo.api.models.message.Message;
    import com.plivo.api.models.message.MessageCreateResponse;
    import com.plivo.api.xml.Response;
    import com.plivo.api.xml.Message;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.web.bind.annotation.PostMapping;
    import org.springframework.web.bind.annotation.RestController;

    import java.io.IOException;

    @SpringBootApplication
    @RestController
    public class ExampleAppApplication {

    	public static void main(String[] args) {
    		SpringApplication.run(ExampleAppApplication.class, args);
    	}
    	
    	@PostMapping(value = "/send_survey/", produces = {"application/json"})
    	public MessageCreateResponse sendSMS() throws IOException, PlivoRestException {
    		Plivo.init("<auth_id>", "<auth_token>");
    		MessageCreateResponse response = Message.creator(
    				"<sender_id>",
    				"<destination_number>",
    				"Did you find out all the information you needed? Please reply \"Yes\" or \"No\"").create();
    		System.out.println(response);
    		return response;
    	}
    	
    	@PostMapping(value = "/survey_response/", produces = {"text/xml"})
    	public String postBody(String From, String To, String Text) throws PlivoXmlException {
    		System.out.println(From + " " + To + " " + Text);
    		String message_body;
    		if (Text.toLowerCase() == "yes") {
    			message_body = "Thank you for your feedback";
    		}
    		else if (Text.toLowerCase() == "no") {
    			message_body = "We apologize for the inconvenience. A representative will contact you to assist you";
    		}
    		else{
    			message_body = String.format("Response received was %1$s, which is invalid. Please reply with either \"Yes\" or \"No\"", Text);
    		}
    		Response response = new Response().children(
    				new Message(To,From,message_body));
    		System.out.println(response.toXmlString());
    		return response.toXmlString();
    	}
    }
    ```

    Replace the auth placeholders with your authentication credentials from the [Plivo console](https://cx.plivo.com/home). Replace the phone number placeholders with actual phone numbers in [E.164 format](https://en.wikipedia.org/wiki/E.164) (for example, +12025551234). In countries other than the US and Canada you can use a [sender ID](/docs/messaging/concepts/sender-id-usage/) for the message source. You must have a Plivo phone number to send messages to the US or Canada; you can buy a Plivo number from Phone Numbers > [Buy Numbers](https://cx.plivo.com/phone-numbers) on the Plivo console or via the [Numbers API](/docs/numbers/phone-numbers#buy-a-phone-number).

    <Note>
      <strong>Note:</strong>
      We recommend that you store your credentials in the `auth_id` and `auth_token` environment variables to avoid the possibility of accidentally committing them to source control. If you do this, you can initialize the client with no arguments and Plivo will automatically fetch the values from the environment variables. You can use <a rel="nofollow" href="https://docs.oracle.com/javase/tutorial/essential/environment/env.html">`System.getenv()`</a> to store and retrieve environment variables when initializing the client.
    </Note>

    <h2 id="api-{{'Test' | slugify}}">Test</h2>

    Save the file and run it.
  </Tab>
</Tabs>
