Textlocal Logo

API Documentation

Sending a Survey via the API

This page will show you how to send a Link Tracked Survey via the API..

Sample Request

<?php
    // Account details
    $apiKey = urlencode('Your apiKey');

    /**********************************
    Get List of Survey IDs on Account
    **********************************/
    // Prepare data for POST request
    $data = array('apikey' => $apiKey);

    // Send the POST request with cURL
    $ch = curl_init('https://api.textlocal.in/get_surveys/');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);

    // Process your response here
    echo $response;

    $responseArray = json_decode($response,true);

    /**********************************
    Get Details of specific survey on Account
    **********************************/

    // Survey details
    $survey_id = $responseArray[0]['id'];

    // Prepare data for POST request
    $data['survey_id'] = $survey_id;

    // Send the POST request with cURL
    $ch = curl_init('https://api.textlocal.in/get_survey_details/');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $surveyDetails = curl_exec($ch);
    curl_close($ch);

    $surveyDetailsArray = json_decode($surveyDetails,true);

    $surveyHex = $surveyDetailsArray['hex'];

    /**********************************
    Get specific contact information
    **********************************/

    // Prepare data for POST request
    unset($data['survey_id']);
    $data['group_id'] = 123456;
    $data['number'] = 918123456789;

    // Send the POST request with cURL
    $ch = curl_init('https://api.textlocal.in/get_contacts/');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $contactInformation = curl_exec($ch);
    curl_close($ch);

    $contactInformationArray = json_decode($contactInformation, true);

    $contactLinkTracking = $contactInformationArray['contact']['linkTracking'];

    $surveyLinkTrackURL = "https://api.textlocal.in/{$surveyHex}/{$contactLinkTracking}";


    /**********************************
    Send SMS
    **********************************/

    // Message details
    $number = $data['number'];
    $sender = urlencode('TXTLCL');
    $message = rawurlencode('Please fill out this survey' . $surveyLinkTrackURL);

    // Prepare data for POST request
    $data = array('apikey' => $apiKey, 'numbers' => $number, "sender" => $sender, "message" => $message);

    // Send the POST request with cURL
    $ch = curl_init('https://api.textlocal.in/send/');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);

    // Process your response here
    echo $response;
?>
<?php
    // Account details
    $apiKey = urlencode('Your apiKey');

    // Prepare data for POST request
    $data = $apiKey;

    /**********************************
    Get List of Survey IDs on Account
     **********************************/

    // Send the POST request with cURL
    $ch = curl_init('https://api.textlocal.in/get_surveys/' . $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);

    // Process your response here
    echo $response;

    $responseArray = json_decode($response,true);

    /**********************************
    Get Details of specific survey on Account
     **********************************/

    // Survey details
    $survey_id = $responseArray[0]['id'];

    // Prepare data for POST request
    $data['survey_id'] = $survey_id;

    // Send the POST request with cURL
    $ch = curl_init('https://api.textlocal.in/get_survey_details/'  . http_build_query($data));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $surveyDetails = curl_exec($ch);
    curl_close($ch);

    $surveyDetailsArray = json_decode($surveyDetails,true);

    $surveyHex = $surveyDetailsArray['hex'];

    /**********************************
    Get specific contact information
     **********************************/

    // Prepare data for POST request
    unset($data['survey_id']);
    $data['group_id'] = 123456;
    $data['number'] = 918123456789;

        // Send the POST request with cURL
    $ch = curl_init('https://api.textlocal.in/get_contacts/' . http_build_query($data));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $contactInformation = curl_exec($ch);
    curl_close($ch);

    $contactInformationArray = json_decode($contactInformation, true);

    $contactLinkTracking = $contactInformationArray['contact']['linkTracking'];

    $surveyLinkTrackURL = "https://api.textlocal.in/{$surveyHex}/{$contactLinkTracking}";


    /**********************************
    Send SMS
     **********************************/

    // Message details
    $number = $data['number'];
    $sender = urlencode('TXTLCL');
    $message = rawurlencode('Please fill out this survey' . $surveyLinkTrackURL);

    // Prepare data for POST request
    $sendData = array('apikey' => $apiKey, 'numbers' => $number, "sender" => $sender, "message" => $message);

    // Send the POST request with cURL
    $ch = curl_init('https://api.textlocal.in/send/' . http_build_query($sendData));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);

    // Process your response here
    echo $response;
?>

Sorry, we do not have an example for Class in the language you have chosen.