> ## 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 Ruby development environment.

    <h3 id="api-{{'Create a Rails controller' | slugify}}">Create a Rails controller</h3>

    Change to the project directory and run this command.

    ```shell theme={null}
    $ rails generate controller Plivo sms
    ```

    This command generates a controller named plivo\_controller in the app/controllers/ directory and a respective view in the app/views/plivo directory. We can delete the view as we don’t need it.

    ```shell theme={null}
    $ rm app/views/plivo/sms.html.erb
    ```

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

    Edit app/controllers/plivo\_controller.rb and paste into it this code.

    ```rb theme={null}
    include Plivo
    include Plivo::Exceptions
    include Plivo::XML

    class PlivoController < ApplicationController
    	protect_from_forgery with: :null_session # disbale CSRF
    	def send_survey
    		api = RestClient.new("<auth_id>","<auth_token>")
    		response = api.messages.create(
    			src:'<sender_id>',
    			dst:'<destination_number>',
    			text:'Did you find out all the information you needed? Please reply "Yes" or "No"'
    		)
    		render json: response.to_s
    	end

    	def survey_response
    		from_number = params[:From]
    		to_number = params[:To]
    		text = params[:Text]
    		puts "From: #{from_number}, To: #{to_number}, Text: #{text}"
    		if text.downcase == "yes"
    			message_body = "Thank you for your feedback"
    		elsif text.downcase=="no"
    			message_body = "We apologize for the inconvenience. A representative will contact you to assist you"
    		else
    			message_body = "Response received was #{text}, which is invalid. Please reply with either Yes or No"
    		end
    		response = Response.new
    		params = {
    			src: to_number,
    			dst: from_number,
    		}
    		response.addMessage(message_body, params)
    		xml = PlivoXML.new(response)
    		puts xml.to_xml
    		render xml: xml.to_xml
    	end
    end
    ```

    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).

    <h3 id="api-{{'Add a route' | slugify}}">Add a route</h3>

    Edit config/routes.rb and change the line

    ```ruby theme={null}
    Rails.application.routes.draw do
      get 'plivo/sms' 
    end
    ```

    to

    ```ruby theme={null}
    Rails.application.routes.draw do
      post 'plivo/send_survey/' => 'plivo#send_survey'
      post 'plivo/survey_response/' => 'plivo#survey_response'
    end
    ```

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

    Save the file and run it.

    ```shell theme={null}
    $ rails server
    ```
  </Tab>
</Tabs>
