Perl Code Samples

REST SMS API: Perl Code Samples

Text Messages

Sending SMS Messages

Sends SMS text messages to a single phone number or an array of phone numbers.

Code Samples

Perl - XML
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use XML::Simple;

$ua = new LWP::UserAgent(keep_alive=>1);

$params = "";
$params.= "User=winnie&Password=the-pooh";
$params.= "&Subject=From Winnie";
$params.= "&Message=I am a Bear of Very Little Brain, and long words bother me";
$params.= "&PhoneNumbers[]=2123456785&PhoneNumbers[]=2123456786";
$params.= "&MessageTypeID=1&StampToSend=1305582245";

my $responde = HTTP::Request->new(POST => "https://app.grouptexting.com/sending/messages?format=xml");
$responde->content_type("application/x-www-form-urlencoded");
$responde->content($params);

$responseObj = $ua->request($responde);

print $responseObj->content."\n--------------------\n";

$responseCode = $responseObj->code;
print 'Response code: ' . $responseCode . "\n";
$isSuccesResponse = $responseCode < 400;

$response = XML::Simple->new->XMLin($responseObj->content);

print 'Status: ' . $response->{Status} . "\n" .
      'Code: ' . $response->{Code} . "\n";
if ($isSuccesResponse) {
    $PhoneNumbers = $response->{Entry}->{PhoneNumbers}->{PhoneNumber};
    $LocalOptOuts = $response->{Entry}->{LocalOptOuts}->{PhoneNumber};
    $GlobalOptOuts = $response->{Entry}->{GlobalOptOuts}->{PhoneNumber};
    print 'Message ID: ' . $response->{Entry}->{ID} . "\n" .
          'Subject: ' . $response->{Entry}->{Subject} . "\n" .
          'Message: ' . $response->{Entry}->{Message} . "\n" .
          'Message Type ID: ' . $response->{Entry}->{MessageTypeID} . "\n" .
          'Total Recipients: ' . $response->{Entry}->{RecipientsCount} . "\n" .
          'Credits Charged: ' . $response->{Entry}->{Credits} . "\n" .
          'Time To Send: ' . $response->{Entry}->{StampToSend} . "\n".
          'Phone Numbers: ' . (ref($PhoneNumbers) eq 'ARRAY' ? join(', ', @{$PhoneNumbers}) : $PhoneNumbers) . "\n" .
          'Locally Opted Out Numbers: ' . (ref($LocalOptOuts) eq 'ARRAY' ? join(', ', @{$LocalOptOuts}) : $LocalOptOuts) . "\n" .
          'Globally Opted Out Numbers: ' . (ref($GlobalOptOuts) eq 'ARRAY' ? join(', ', @{$GlobalOptOuts}) : $GlobalOptOuts) . "\n";
} else {
    $errors = $response->{Errors}->{Error};
    print 'Errors: ' .(ref($errors) eq 'ARRAY' ? join(', ', @{$errors}) : $errors) . "\n";
}                      
Perl - JSON
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use JSON::XS;

$ua = new LWP::UserAgent(keep_alive=>1);

$params = "";
$params.= "User=winnie&Password=the-pooh";
$params.= "&Subject=From Winnie";
$params.= "&Message=I am a Bear of Very Little Brain, and long words bother me";
$params.= "&PhoneNumbers[]=2123456785&PhoneNumbers[]=2123456786";
$params.= "&StampToSend=1305582245";

my $responde = HTTP::Request->new(POST => "https://app.grouptexting.com/sending/messages?format=json");
$responde->content_type("application/x-www-form-urlencoded");
$responde->content($params);

$responseObj = $ua->request($responde);

print $responseObj->content."\n--------------------\n";

$responseCode = $responseObj->code;
print 'Response code: ' . $responseCode . "\n";
$isSuccesResponse = $responseCode < 400;

$response = JSON::XS->new->decode ($responseObj->content);

print 'Status: ' . $response->{Response}->{Status} . "\n" .
      'Code: ' . $response->{Response}->{Code} . "\n";
if ($isSuccesResponse) {
    print 'Message ID: ' . $response->{Response}->{Entry}->{ID} . "\n".
          'Subject: ' . $response->{Response}->{Entry}->{Subject} . "\n" .
          'Message: ' . $response->{Response}->{Entry}->{Message} . "\n" .
          'Total Recipients: ' . $response->{Response}->{Entry}->{RecipientsCount} . "\n" .
          'Credits Charged: ' . $response->{Response}->{Entry}->{Credits} . "\n" .
          'Time To Send: ' . $response->{Response}->{Entry}->{StampToSend} . "\n".
          'Phone Numbers: ' . join(', ', @{$response->{Response}->{Entry}->{PhoneNumbers}}) . "\n" .
          'Locally Opted Out Numbers: ' . join(', ', @{$response->{Response}->{Entry}->{LocalOptOuts}}) . "\n" .
          'Globally Opted Out Numbers: ' . join(', ', @{$response->{Response}->{Entry}->{GlobalOptOuts}}) . "\n";
} else {
    foreach $err (@{$response->{Response}->{Errors}}) {
        print 'Error: ' . $err . "\n";
    }
}

                      

Inbox

Inbox & Folders

When working with the Inbox and Folder you can perform nine actions: Post (Add New Folder), Put (Update A Folder/Move A Message Between Folders), Delete (Delete A Message/Folder), Get (Get Inbox Message/Folder By ID), Index (Get All Messages/All Folders). The code samples below use the shared libraries:
· SMSTextingAPI.pm
· SmsTextingJsonDecoder.pm
· SmsTextingXmlDecoder.pm
You can download them, along with the code samples here: PerlLib.zip.

Code Samples - Inbox Messages

Perl - XML
#!/usr/bin/perl

use warnings;
use strict;
use SmsTextingAPI;
use Data::Dumper;
use feature qw(say);

say 'XML encoding.';
my $sms = new SmsTextingAPI("demouser", "password", SmsTextingAPI::XML, "https://app.grouptexting.com");


say 'Get incomingMessages';
my $response =  $sms->getAll(SmsTextingAPI::INCOMING_MESSAGE);
say Dumper($response);

my $incomingMessageId = $response->{Entries}[0]->{ID};
my $incomingMessageId2 = $response->{Entries}[1]->{ID};
my $incomingMessageIdsArray = [$incomingMessageId, $incomingMessageId2];

say 'Move incomingMessages';
$response = $sms->moveMessagesToFolder('88', $incomingMessageIdsArray );
say Dumper($response);


say 'Get incomingMessage';
$response =  $sms->get(SmsTextingAPI::INCOMING_MESSAGE, $incomingMessageId2);
say Dumper($response);


say 'Delete incomingMessage';
$response =  $sms->delete(SmsTextingAPI::INCOMING_MESSAGE, $incomingMessageId);
say Dumper($response);


say 'Second delete. try to get error';
$response =  $sms->delete(SmsTextingAPI::INCOMING_MESSAGE, $incomingMessageId);
say Dumper($response);
Perl - JSON
#!/usr/bin/perl

use warnings;
use strict;
use SmsTextingAPI;
use Data::Dumper;
use feature qw(say);

say 'JSON encoding.';
$sms = new SmsTextingAPI("demouser", "password", SmsTextingAPI::JSON, "https://app.grouptexting.com");

say 'Get incomingMessages';
$response =  $sms->getAll(SmsTextingAPI::INCOMING_MESSAGE);
say Dumper($response);

$incomingMessageId = $response->{Entries}[0]->{ID};


say 'Move incomingMessage';
$response = $sms->moveMessagesToFolder('75', $incomingMessageId);
say Dumper($response);

say 'Get incomingMessage';
$response =  $sms->get(SmsTextingAPI::INCOMING_MESSAGE, $incomingMessageId);
say Dumper($response);


say 'Delete incomingMessage';
$response =  $sms->delete(SmsTextingAPI::INCOMING_MESSAGE, $incomingMessageId);
say Dumper($response);


say 'Second delete. try to get error';
$response =  $sms->delete(SmsTextingAPI::INCOMING_MESSAGE, $incomingMessageId);
say Dumper($response);

Code Samples - Inbox Folders

Perl - XML
#!/usr/bin/perl

use warnings;
use strict;
use SmsTextingAPI;
use Data::Dumper;
use feature qw(say);

say 'XML encoding.';
my $sms = new SmsTextingAPI("demouser", "password", SmsTextingAPI::XML, "https://app.grouptexting.com");

say 'Get folders';
my $response =  $sms->getAll(SmsTextingAPI::FOLDER);
say Dumper($response);


say 'Create folder';
$response = $sms->put(SmsTextingAPI::FOLDER,
    'Name'        => 'Customers');
say Dumper($response);


say 'Get folder';
my $folderId = $response->{Entry}->{ID};
$response =  $sms->get(SmsTextingAPI::FOLDER, $folderId);
say Dumper($response);


say 'Update folder';
my $folder = $response->{Entry};
$folder->{'Name'} = 'Customers2';
$folder->{ID} = $folderId;
$response = $sms->put(SmsTextingAPI::FOLDER, %$folder);
say Dumper($response);


say 'Delete folder';
$response =  $sms->delete(SmsTextingAPI::FOLDER, $folderId);
say Dumper($response);


say 'Second delete. try to get error';
$response =  $sms->delete(SmsTextingAPI::FOLDER, $folderId);
say Dumper($response);
Perl - JSON
#!/usr/bin/perl

use warnings;
use strict;
use SmsTextingAPI;
use Data::Dumper;
use feature qw(say);

say 'JSON encoding.';
$sms = new SmsTextingAPI("demouser", "password", SmsTextingAPI::JSON, "https://app.grouptexting.com");

say 'Get folders';
$response =  $sms->getAll(SmsTextingAPI::FOLDER);
say Dumper($response);


say 'Create folder';
$response = $sms->put(SmsTextingAPI::FOLDER,
    'Name'        => 'Customers');
say Dumper($response);


say 'Get folder';
$folderId = $response->{Entry}->{ID};
$response =  $sms->get(SmsTextingAPI::FOLDER, $folderId);
say Dumper($response);


say 'Update folder';
$folder = $response->{Entry};
$folder->{'Name'} = 'Customers2';
$folder->{ID} = $folderId;
$response = $sms->put(SmsTextingAPI::FOLDER, %$folder);
say Dumper($response);


say 'Delete folder';
$response =  $sms->delete(SmsTextingAPI::FOLDER, $folderId);
say Dumper($response);


say 'Second delete. try to get error';
$response =  $sms->delete(SmsTextingAPI::FOLDER, $folderId);
say Dumper($response);

Keywords

Check Keyword Availability

Check whether a Keyword is available to rent on Group Texting.

Code Samples

Perl - XML
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use XML::Simple;

$ua = new LWP::UserAgent(keep_alive=>1);

$params = "";
$params.= "User=winnie&Password=the-pooh";
$params.= "&Keyword=honey";

my $responde = HTTP::Request->new(GET => "https://app.grouptexting.com/keywords/new?format=xml&".$params);

$responseObj = $ua->request($responde);

print $responseObj->content."\n--------------------\n";

$responseCode = $responseObj->code;
print 'Response code: ' . $responseCode . "\n";
$isSuccesResponse = $responseCode < 400;

$response = XML::Simple->new->XMLin($responseObj->content);

print 'Status: ' . $response->{Status} . "\n" .
      'Code: ' . $response->{Code} . "\n";
if ($isSuccesResponse) {
    print 'Keyword: ' . $response->{Entry}->{Keyword} . "\n".
          'Availability: ' . $response->{Entry}->{Available} . "\n";
} else {
    $errors = $response->{Errors}->{Error};
    print 'Errors: ' .(ref($errors) eq 'ARRAY' ? join(', ', @{$errors}) : $errors) . "\n";
}
                      
Perl - JSON
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use JSON::XS;

$ua = new LWP::UserAgent(keep_alive=>1);

$params = "";
$params.= "User=winnie&Password=the-pooh";
$params.= "&Keyword=honey";

my $responde = HTTP::Request->new(GET => "https://app.grouptexting.com/keywords/new?format=json&".$params);

$responseObj = $ua->request($responde);

print $responseObj->content."\n--------------------\n";

$responseCode = $responseObj->code;
print 'Response code: ' . $responseCode . "\n";
$isSuccesResponse = $responseCode < 400;

$response = JSON::XS->new->decode ($responseObj->content);

print 'Status: ' . $response->{Response}->{Status} . "\n" .
      'Code: ' . $response->{Response}->{Code} . "\n";
if ($isSuccesResponse) {
    print 'Keyword: ' . $response->{Response}->{Entry}->{Keyword} . "\n".
          'Availability: ' . $response->{Response}->{Entry}->{Available} . "\n";
} else {
    foreach $err (@{$response->{Response}->{Errors}}) {
        print 'Error: ' . $err . "\n";
    }
}

                      

Rent Keyword

Rents a Keyword for use on Group Texting. You may rent a Keyword using a credit card you have stored in your Group Texting account, or you may pass credit card details when you call the API.

Code Samples - Stored Card

Perl - XML
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use XML::Simple;

$ua = new LWP::UserAgent(keep_alive=>1);

$params = "";
$params.= "User=demo&Password=texting121212";
$params.= "&Subject=From Winnie";
$params.= "&Keyword=honey";
$params.= "&StoredCreditCard=1111";


my $responde = HTTP::Request->new(POST => "https://app.grouptexting.com/keywords?format=xml");
$responde->content_type("application/x-www-form-urlencoded");
$responde->content($params);

$responseObj = $ua->request($responde);

print $responseObj->content."\n--------------------\n";

$responseCode = $responseObj->code;
print 'Response code: ' . $responseCode . "\n";
$isSuccesResponse = $responseCode < 400;

$response = XML::Simple->new->XMLin($responseObj->content);

print 'Status: ' . $response->{Status} . "\n" .
      'Code: ' . $response->{Code} . "\n";
if ($isSuccesResponse) {
    $groups = $response->{Entry}->{ContactGroupIDs}->{Group};
    print 'Keyword ID: ' . $response->{Entry}->{ID} . "\n".
          'Keyword: ' . $response->{Entry}->{Keyword} . "\n" .
          'Is double opt-in enabled: ' .  $response->{Entry}->{EnableDoubleOptIn} . "\n" .
          'Confirm message: ' . $response->{Entry}->{ConfirmMessage} . "\n" .
          'Join message: ' . $response->{Entry}->{JoinMessage} . "\n" .
          'Forward email: ' . $response->{Entry}->{ForwardEmail} . "\n" .
          'Forward url: ' . $response->{Entry}->{ForwardUrl} . "\n" .
          'Groups: ' . (ref($groups) eq 'ARRAY' ? join(', ', @{$groups}) : $groups)."\n";
} else {
    $errors = $response->{Errors}->{Error};
    print 'Errors: ' .(ref($errors) eq 'ARRAY' ? join(', ', @{$errors}) : $errors) . "\n";
}

                      
Perl - JSON
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use JSON::XS;

$ua = new LWP::UserAgent(keep_alive=>1);

$params = "";
$params.= "User=demo&Password=texting121212";
$params.= "&Subject=From Winnie";
$params.= "&Keyword=honey";
$params.= "&StoredCreditCard=1111";


my $responde = HTTP::Request->new(POST => "https://app.grouptexting.com/keywords?format=json");
$responde->content_type("application/x-www-form-urlencoded");
$responde->content($params);

$responseObj = $ua->request($responde);

print $responseObj->content."\n--------------------\n";

$responseCode = $responseObj->code;
print 'Response code: ' . $responseCode . "\n";
$isSuccesResponse = $responseCode < 400;

$response = JSON::XS->new->decode ($responseObj->content);

print 'Status: ' . $response->{Response}->{Status} . "\n" .
      'Code: ' . $response->{Response}->{Code} . "\n";
if ($isSuccesResponse) {
    print 'Keyword ID: ' . $response->{Response}->{Entry}->{ID} . "\n".
          'Keyword: ' . $response->{Response}->{Entry}->{Keyword} . "\n" .
          'Is double opt-in enabled: ' . $response->{Response}->{Entry}->{EnableDoubleOptIn} . "\n" .
          'Confirm message: ' . $response->{Response}->{Entry}->{ConfirmMessage} . "\n" .
          'Join message: ' . $response->{Response}->{Entry}->{JoinMessage} . "\n" .
          'Forward email: ' . $response->{Response}->{Entry}->{ForwardEmail} . "\n" .
          'Forward url: ' . $response->{Response}->{Entry}->{ForwardUrl} . "\n" .
          'Groups: ' . join(', ' , @{$response->{Response}->{Entry}->{ContactGroupIDs}}) . "\n";
} else {
    foreach $err (@{$response->{Response}->{Errors}}) {
        print 'Error: ' . $err . "\n";
    }
}

                      

Code Samples - Non-Stored Card

Perl - XML
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use XML::Simple;

$ua = new LWP::UserAgent(keep_alive=>1);

$params = "";
$params.= "User=winnie&Password=the-pooh";
$params.= "&Subject=From Winnie";
$params.= "&Keyword=honey";
$params.= "&FirstName=Winnie";
$params.= "&LastName=The Pooh";
$params.= "&Street=Hollow tree, under the name of Mr. Sanders";
$params.= "&City=Hundred Acre Woods";
$params.= "&State=New York";
$params.= "&Zip=12345";
$params.= "&Country=US";
$params.= "&CreditCardTypeID=Visa";
$params.= "&Number=4111111111111111";
$params.= "&SecurityCode=123";
$params.= "&ExpirationMonth=10";
$params.= "&ExpirationYear=2017";


my $responde = HTTP::Request->new(POST => "https://app.grouptexting.com/keywords?format=xml");
$responde->content_type("application/x-www-form-urlencoded");
$responde->content($params);

$responseObj = $ua->request($responde);

print $responseObj->content."\n--------------------\n";

$responseCode = $responseObj->code;
print 'Response code: ' . $responseCode . "\n";
$isSuccesResponse = $responseCode < 400;

$response = XML::Simple->new->XMLin($responseObj->content);

print 'Status: ' . $response->{Status} . "\n" .
      'Code: ' . $response->{Code} . "\n";
if ($isSuccesResponse) {
    $groups = $response->{Entry}->{ContactGroupIDs}->{Group};
    print 'Keyword ID: ' . $response->{Entry}->{ID} . "\n".
          'Keyword: ' . $response->{Entry}->{Keyword} . "\n" .
          'Is double opt-in enabled: ' .  $response->{Entry}->{EnableDoubleOptIn} . "\n" .
          'Confirm message: ' . $response->{Entry}->{ConfirmMessage} . "\n" .
          'Join message: ' . $response->{Entry}->{JoinMessage} . "\n" .
          'Forward email: ' . $response->{Entry}->{ForwardEmail} . "\n" .
          'Forward url: ' . $response->{Entry}->{ForwardUrl} . "\n" .
          'Groups: ' . (ref($groups) eq 'ARRAY' ? join(', ', @{$groups}) : $groups)."\n";
} else {
    $errors = $response->{Errors}->{Error};
    print 'Errors: ' .(ref($errors) eq 'ARRAY' ? join(', ', @{$errors}) : $errors) . "\n";
}

                      
Perl - JSON
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use JSON::XS;

$ua = new LWP::UserAgent(keep_alive=>1);

$params = "";
$params.= "User=winnie&Password=the-pooh";
$params.= "&Subject=From Winnie";
$params.= "&Keyword=honey";
$params.= "&FirstName=Winnie";
$params.= "&LastName=The Pooh";
$params.= "&Street=Hollow tree, under the name of Mr. Sanders";
$params.= "&City=Hundred Acre Woods";
$params.= "&State=New York";
$params.= "&Zip=12345";
$params.= "&Country=US";
$params.= "&CreditCardTypeID=Visa";
$params.= "&Number=4111111111111111";
$params.= "&SecurityCode=123";
$params.= "&ExpirationMonth=10";
$params.= "&ExpirationYear=2017";


my $responde = HTTP::Request->new(POST => "https://app.grouptexting.com/keywords?format=json");
$responde->content_type("application/x-www-form-urlencoded");
$responde->content($params);

$responseObj = $ua->request($responde);

print $responseObj->content."\n--------------------\n";

$responseCode = $responseObj->code;
print 'Response code: ' . $responseCode . "\n";
$isSuccesResponse = $responseCode < 400;

$response = JSON::XS->new->decode ($responseObj->content);

print 'Status: ' . $response->{Response}->{Status} . "\n" .
      'Code: ' . $response->{Response}->{Code} . "\n";
if ($isSuccesResponse) {
    print 'Keyword ID: ' . $response->{Response}->{Entry}->{ID} . "\n".
          'Keyword: ' . $response->{Response}->{Entry}->{Keyword} . "\n" .
          'Is double opt-in enabled: ' . $response->{Response}->{Entry}->{EnableDoubleOptIn} . "\n" .
          'Confirm message: ' . $response->{Response}->{Entry}->{ConfirmMessage} . "\n" .
          'Join message: ' . $response->{Response}->{Entry}->{JoinMessage} . "\n" .
          'Forward email: ' . $response->{Response}->{Entry}->{ForwardEmail} . "\n" .
          'Forward url: ' . $response->{Response}->{Entry}->{ForwardUrl} . "\n" .
          'Groups: ' . join(', ' , @{$response->{Response}->{Entry}->{ContactGroupIDs}}) . "\n";
} else {
    foreach $err (@{$response->{Response}->{Errors}}) {
        print 'Error: ' . $err . "\n";
    }
}

                      

Setup A Keyword

Configures an active Keyword for use on Group Texting.

Code Samples

Perl - XML
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use XML::Simple;

$ua = new LWP::UserAgent(keep_alive=>1);

$params = "";
$params.= "User=winnie&Password=the-pooh";
$params.= "&EnableDoubleOptIn=1";
$params.= "&ConfirmMessage=Reply Y to join our sweetest list";
$params.= "&JoinMessage=The only reason for being a bee that I know of, is to make honey. And the only reason for making honey, is so as I can eat it.";
$params.= '&[email protected]';
$params.= "&ForwardUrl=http://bear-alliance.co.uk/honey-donations/";
$params.= "&ContactGroupIDs[]=honey";
$params.= "&ContactGroupIDs[]=lovers";

my $responde = HTTP::Request->new(POST => "https://app.grouptexting.com/keywords/honey?format=xml");
$responde->content_type("application/x-www-form-urlencoded");
$responde->content($params);

$responseObj = $ua->request($responde);

print $responseObj->content."\n--------------------\n";

$responseCode = $responseObj->code;
print 'Response code: ' . $responseCode . "\n";
$isSuccesResponse = $responseCode < 400;

$response = XML::Simple->new->XMLin($responseObj->content);#(ForceArray => 1)

print 'Status: ' . $response->{Status} . "\n" .
      'Code: ' . $response->{Code} . "\n";
if ($isSuccesResponse) {
    $groups = $response->{Entry}->{ContactGroupIDs}->{Group};
    print 'Keyword ID: ' . $response->{Entry}->{ID} . "\n".
          'Keyword: ' . $response->{Entry}->{Keyword} . "\n" .
          'Is double opt-in enabled: ' .  $response->{Entry}->{EnableDoubleOptIn} . "\n" .
          'Confirm message: ' . $response->{Entry}->{ConfirmMessage} . "\n" .
          'Join message: ' . $response->{Entry}->{JoinMessage} . "\n" .
          'Forward email: ' . $response->{Entry}->{ForwardEmail} . "\n" .
          'Forward url: ' . $response->{Entry}->{ForwardUrl} . "\n" .
          'Groups: ' . (ref($groups) eq 'ARRAY' ? join(', ', @{$groups}) : $groups)."\n";
} else {
    $errors = $response->{Errors}->{Error};
    print 'Errors: ' .(ref($errors) eq 'ARRAY' ? join(', ', @{$errors}) : $errors) . "\n";
}


      

                      
Perl - JSON
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use JSON::XS;

$ua = new LWP::UserAgent(keep_alive=>1);

$params = "";
$params.= "User=winnie&Password=the-pooh";
$params.= "&EnableDoubleOptIn=1";
$params.= "&ConfirmMessage=Reply Y to join our sweetest list";
$params.= "&JoinMessage=The only reason for being a bee that I know of, is to make honey. And the only reason for making honey, is so as I can eat it.";
$params.= '&[email protected]';
$params.= "&ForwardUrl=http://bear-alliance.co.uk/honey-donations/";
$params.= "&ContactGroupIDs[]=honey";
$params.= "&ContactGroupIDs[]=lovers";

my $responde = HTTP::Request->new(POST => "https://app.grouptexting.com/keywords/honey?format=json");
$responde->content_type("application/x-www-form-urlencoded");
$responde->content($params);

$responseObj = $ua->request($responde);

print $responseObj->content."\n--------------------\n";

$responseCode = $responseObj->code;
print 'Response code: ' . $responseCode . "\n";
$isSuccesResponse = $responseCode < 400;

$response = JSON::XS->new->decode ($responseObj->content);

print 'Status: ' . $response->{Response}->{Status} . "\n" .
      'Code: ' . $response->{Response}->{Code} . "\n";
if ($isSuccesResponse) {
    print 'Keyword ID: ' . $response->{Response}->{Entry}->{ID} . "\n".
          'Keyword: ' . $response->{Response}->{Entry}->{Keyword} . "\n" .
          'Is double opt-in enabled: ' .  $response->{Response}->{Entry}->{EnableDoubleOptIn} . "\n" .
          'Confirm message: ' . $response->{Response}->{Entry}->{ConfirmMessage} . "\n" .
          'Join message: ' . $response->{Response}->{Entry}->{JoinMessage} . "\n" .
          'Forward email: ' . $response->{Response}->{Entry}->{ForwardEmail} . "\n" .
          'Forward url: ' . $response->{Response}->{Entry}->{ForwardUrl} . "\n" .
          'Groups: ' . join(', ', @{$response->{Response}->{Entry}->{ContactGroupIDs}})."\n";
} else {
    foreach $err (@{$response->{Response}->{Errors}}) {
        print 'Error: ' . $err . "\n";
    }
}

      

                      

Cancel A Keyword

Cancels an active Keyword on Group Texting.

Code Samples

Perl - XML
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use XML::Simple;

$ua = new LWP::UserAgent(keep_alive=>1);

$params = "";
$params.= "User=winnie&Password=the-pooh";

my $responde = HTTP::Request->new(POST => "https://app.grouptexting.com/keywords/honey?format=xml&_method=DELETE");
$responde->content_type("application/x-www-form-urlencoded");
$responde->content($params);

$responseObj = $ua->request($responde);

print $responseObj->content."\n--------------------\n";

$responseCode = $responseObj->code;
print 'Response code: ' . $responseCode . "\n";
$isSuccesResponse = $responseCode < 400;


if (!$isSuccesResponse) {
    $response = XML::Simple->new->XMLin($responseObj->content);
    print 'Status: ' . $response->{Status} . "\n" .
          'Code: ' . $response->{Code} . "\n";
    $errors = $response->{Errors}->{Error};
    print 'Errors: ' .(ref($errors) eq 'ARRAY' ? join(', ', @{$errors}) : $errors) . "\n";
}


                      
Perl - JSON
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use JSON::XS;

$ua = new LWP::UserAgent(keep_alive=>1);

$params = "";
$params.= "User=winnie&Password=the-pooh";

my $responde = HTTP::Request->new(POST => "https://app.grouptexting.com/keywords/honey?format=json&_method=DELETE");
$responde->content_type("application/x-www-form-urlencoded");
$responde->content($params);

$responseObj = $ua->request($responde);

print $responseObj->content."\n--------------------\n";


$responseCode = $responseObj->code;
print 'Response code: ' . $responseCode . "\n";
$isSuccesResponse = $responseCode < 400;

if (!$isSuccesResponse) {
    $response = JSON::XS->new->decode ($responseObj->content);
    print 'Status: ' . $response->{Response}->{Status} . "\n" .
          'Code: ' . $response->{Response}->{Code} . "\n";
    foreach $err (@{$response->{Response}->{Errors}}) {
        print 'Error: ' . $err . "\n";
    }
}


                      

Credits

Check Credit Balance

Checks credit balances on your account.

Code Samples

Perl - XML
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use XML::Simple;

$ua = new LWP::UserAgent(keep_alive=>1);

$params = "";
$params.= "User=winnie&Password=the-pooh";

my $responde = HTTP::Request->new(GET => "https://app.grouptexting.com/billing/credits/get?format=xml&".$params);

$responseObj = $ua->request($responde);

print $responseObj->content."\n--------------------\n";

$responseCode = $responseObj->code;
print 'Response code: ' . $responseCode . "\n";
$isSuccesResponse = $responseCode < 400;

$response = XML::Simple->new->XMLin($responseObj->content);

print 'Status: ' . $response->{Status} . "\n" .
      'Code: ' . $response->{Code} . "\n";
if ($isSuccesResponse) {
    print 'Plan credits: ' . $response->{Entry}->{PlanCredits} . "\n" .
          'Anytime credits: ' . $response->{Entry}->{AnytimeCredits} . "\n" .
          'Total: ' . $response->{Entry}->{TotalCredits} . "\n";
} else {
    $errors = $response->{Errors}->{Error};
    print 'Errors: ' .(ref($errors) eq 'ARRAY' ? join(', ', @{$errors}) : $errors) . "\n";
}

                      
Perl - JSON
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use JSON::XS;

$ua = new LWP::UserAgent(keep_alive=>1);

$params = "";
$params.= "User=winnie&Password=the-pooh";

my $responde = HTTP::Request->new(GET => "https://app.grouptexting.com/billing/credits/get?format=json&".$params);

$responseObj = $ua->request($responde);

print $responseObj->content."\n--------------------\n";

$responseCode = $responseObj->code;
print 'Response code: ' . $responseCode . "\n";
$isSuccesResponse = $responseCode < 400;

$response = JSON::XS->new->decode ($responseObj->content);

print 'Status: ' . $response->{Response}->{Status} . "\n" .
      'Code: ' . $response->{Response}->{Code} . "\n";
if ($isSuccesResponse) {
    print 'Plan credits: ' . $response->{Response}->{Entry}->{PlanCredits} . "\n" .
          'Anytime credits: ' . $response->{Response}->{Entry}->{AnytimeCredits} . "\n" .
          'Total: ' . $response->{Response}->{Entry}->{TotalCredits} . "\n";
} else {
    foreach $err (@{$response->{Response}->{Errors}}) {
        print 'Error: ' . $err . "\n";
    }
}

                      

Buy Credits

Buys more credits for your account. You may purchase credits using a credit card you have stored in your Group Texting account, or you may pass credit card details when you call the API.

Code Samples - Stored Card

Perl - XML
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use XML::Simple;

$ua = new LWP::UserAgent(keep_alive=>1);

$params = "";
$params.= "User=demo&Password=texting121212";
$params.= "&NumberOfCredits=1000";
$params.= "&CouponCode=honey2011";
$params.= "&StoredCreditCard=1111";


my $responde = HTTP::Request->new(POST => "https://app.grouptexting.com/billing/credits?format=xml");
$responde->content_type("application/x-www-form-urlencoded");
$responde->content($params);

$responseObj = $ua->request($responde);

print $responseObj->content."\n--------------------\n";

$responseCode = $responseObj->code;
print 'Response code: ' . $responseCode . "\n";
$isSuccesResponse = $responseCode < 400;

$response = XML::Simple->new->XMLin($responseObj->content);

print 'Status: ' . $response->{Status} . "\n" .
      'Code: ' . $response->{Code} . "\n";
if ($isSuccesResponse) {
    print 'Credits purchased: ' . $response->{Entry}->{BoughtCredits} . "\n" .
          'Amount charged, $: ' . $response->{Entry}->{Amount} . "\n" .
          'Discount, $: ' . $response->{Entry}->{Discount} . "\n" .
          'Plan credits: ' . $response->{Entry}->{PlanCredits} . "\n" .
          'Anytime credits: ' . $response->{Entry}->{AnytimeCredits} . "\n" .
          'Total: ' . $response->{Entry}->{TotalCredits} . "\n";
} else {
    $errors = $response->{Errors}->{Error};
    print 'Errors: ' .(ref($errors) eq 'ARRAY' ? join(', ', @{$errors}) : $errors) . "\n";
}


                      
Perl - JSON
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use JSON::XS;

$ua = new LWP::UserAgent(keep_alive=>1);

$params = "";
$params.= "User=demo&Password=texting121212";
$params.= "&NumberOfCredits=1000";
$params.= "&CouponCode=honey2011";
$params.= "&StoredCreditCard=1111";


my $responde = HTTP::Request->new(POST => "https://app.grouptexting.com/billing/credits?format=json");
$responde->content_type("application/x-www-form-urlencoded");
$responde->content($params);

$responseObj = $ua->request($responde);

print $responseObj->content."\n--------------------\n";

$responseCode = $responseObj->code;
print 'Response code: ' . $responseCode . "\n";
$isSuccesResponse = $responseCode < 400;

$response = JSON::XS->new->decode ($responseObj->content);

print 'Status: ' . $response->{Response}->{Status} . "\n" .
      'Code: ' . $response->{Response}->{Code} . "\n";
if ($isSuccesResponse) {
    print 'Credits purchased: ' . $response->{Response}->{Entry}->{BoughtCredits} . "\n" .
          'Amount charged, $: ' . $response->{Response}->{Entry}->{Amount} . "\n" .
          'Discount, $: ' . $response->{Response}->{Entry}->{Discount} . "\n" .
          'Plan credits: ' . $response->{Response}->{Entry}->{PlanCredits} . "\n" .
          'Anytime credits: ' . $response->{Response}->{Entry}->{AnytimeCredits} . "\n" .
          'Total: ' . $response->{Response}->{Entry}->{TotalCredits} . "\n";
} else {
    foreach $err (@{$response->{Response}->{Errors}}) {
        print 'Error: ' . $err . "\n";
    }
}



                      

Code Samples - Non-Stored Card

Perl - XML
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use XML::Simple;

$ua = new LWP::UserAgent(keep_alive=>1);

$params = "";
$params.= "User=winnie&Password=the-pooh";
$params.= "&NumberOfCredits=1000";
$params.= "&CouponCode=honey2011";
$params.= "&FirstName=Winnie";
$params.= "&LastName=The Pooh";
$params.= "&Street=Hollow tree, under the name of Mr. Sanders";
$params.= "&City=Hundred Acre Woods";
$params.= "&State=New York";
$params.= "&Zip=12345";
$params.= "&Country=US";
$params.= "&CreditCardTypeID=Visa";
$params.= "&Number=4111111111111111";
$params.= "&SecurityCode=123";
$params.= "&ExpirationMonth=10";
$params.= "&ExpirationYear=2017";


my $responde = HTTP::Request->new(POST => "https://app.grouptexting.com/billing/credits?format=xml");
$responde->content_type("application/x-www-form-urlencoded");
$responde->content($params);

$responseObj = $ua->request($responde);

print $responseObj->content."\n--------------------\n";

$responseCode = $responseObj->code;
print 'Response code: ' . $responseCode . "\n";
$isSuccesResponse = $responseCode < 400;

$response = XML::Simple->new->XMLin($responseObj->content);

print 'Status: ' . $response->{Status} . "\n" .
      'Code: ' . $response->{Code} . "\n";
if ($isSuccesResponse) {
    print 'Credits purchased: ' . $response->{Entry}->{BoughtCredits} . "\n" .
          'Amount charged, $: ' . $response->{Entry}->{Amount} . "\n" .
          'Discount, $: ' . $response->{Entry}->{Discount} . "\n" .
          'Plan credits: ' . $response->{Entry}->{PlanCredits} . "\n" .
          'Anytime credits: ' . $response->{Entry}->{AnytimeCredits} . "\n" .
          'Total: ' . $response->{Entry}->{TotalCredits} . "\n";
} else {
    $errors = $response->{Errors}->{Error};
    print 'Errors: ' .(ref($errors) eq 'ARRAY' ? join(', ', @{$errors}) : $errors) . "\n";
}


                      
Perl - JSON
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use JSON::XS;

$ua = new LWP::UserAgent(keep_alive=>1);

$params = "";
$params.= "User=winnie&Password=the-pooh";
$params.= "&NumberOfCredits=1000";
$params.= "&CouponCode=honey2011";
$params.= "&FirstName=Winnie";
$params.= "&LastName=The Pooh";
$params.= "&Street=Hollow tree, under the name of Mr. Sanders";
$params.= "&City=Hundred Acre Woods";
$params.= "&State=New York";
$params.= "&Zip=12345";
$params.= "&Country=US";
$params.= "&CreditCardTypeID=Visa";
$params.= "&Number=4111111111111111";
$params.= "&SecurityCode=123";
$params.= "&ExpirationMonth=10";
$params.= "&ExpirationYear=2017";


my $responde = HTTP::Request->new(POST => "https://app.grouptexting.com/billing/credits?format=json");
$responde->content_type("application/x-www-form-urlencoded");
$responde->content($params);

$responseObj = $ua->request($responde);

print $responseObj->content."\n--------------------\n";

$responseCode = $responseObj->code;
print 'Response code: ' . $responseCode . "\n";
$isSuccesResponse = $responseCode < 400;

$response = JSON::XS->new->decode ($responseObj->content);

print 'Status: ' . $response->{Response}->{Status} . "\n" .
      'Code: ' . $response->{Response}->{Code} . "\n";
if ($isSuccesResponse) {
    print 'Credits purchased: ' . $response->{Response}->{Entry}->{BoughtCredits} . "\n" .
          'Amount charged, $: ' . $response->{Response}->{Entry}->{Amount} . "\n" .
          'Discount, $: ' . $response->{Response}->{Entry}->{Discount} . "\n" .
          'Plan credits: ' . $response->{Response}->{Entry}->{PlanCredits} . "\n" .
          'Anytime credits: ' . $response->{Response}->{Entry}->{AnytimeCredits} . "\n" .
          'Total: ' . $response->{Response}->{Entry}->{TotalCredits} . "\n";
} else {
    foreach $err (@{$response->{Response}->{Errors}}) {
        print 'Error: ' . $err . "\n";
    }
}


                      

Contacts

Contacts

When working with Contacts you can perform five actions: Post (Add New Contact), Put (Update/Edit A Contact), Delete (Delete A Contact), Get (Get Contact By ID), Index (Get All Contacts). The code samples below use shared libraries:
· SMSTextingAPI.pm
· SmsTextingJsonDecoder.pm
· SmsTextingXmlDecoder.pm
You can download them, along with the code samples here: PerlLib.zip.

Code Samples

Perl - XML
#!/usr/bin/perl

use warnings;
use strict;
use SmsTextingAPI;
use Data::Dumper;
use feature qw(say);

say 'XML encoding.';
my $sms = new SmsTextingAPI("demouser", "password", SmsTextingAPI::XML, "https://app.grouptexting.com");

say 'Get contacts';
my $response =  $sms->getAll(SmsTextingAPI::CONTACT, 
    'source'        => 'upload',
    'optout'        => 'false',
    'group'         => 'Honey Lovers',
    'sortBy'        => 'PhoneNumber',
    'sortDir'       => 'asc',
    'itemsPerPage'  => '10',
    'page'          => '3');
say Dumper($response);


say 'Create contact';
$response = $sms->put(SmsTextingAPI::CONTACT,
    'PhoneNumber' => '2123456945',
    'FirstName'   => 'Piglet',
    'LastName'    => 'P.',
    'Email'       => '[email protected]',
    'Note'        => 'It is hard to be brave, when you are only a Very Small Animal.',
    'Groups'   => ['Friends', 'Neighbors']);
say Dumper($response);


say 'Get contact';
my $contactId = $response->{Entry}->{ID};
$response =  $sms->get(SmsTextingAPI::CONTACT, $contactId);
say Dumper($response);


say 'Update contact';
my $contact = $response->{Entry};
$contact->{'LastName'} = 'test';
$response = $sms->put(SmsTextingAPI::CONTACT, %$contact);
say Dumper($response);


say 'Delete contact';
$response =  $sms->delete(SmsTextingAPI::CONTACT, $contactId);
say Dumper($response);


say 'Second delete. try to get error';
$response =  $sms->delete(SmsTextingAPI::CONTACT, $contactId);
say Dumper($response);
                     
Perl - JSON
#!/usr/bin/perl

use warnings;
use strict;
use SmsTextingAPI;
use Data::Dumper;
use feature qw(say);

say 'JSON encoding.';
$sms = new SmsTextingAPI("demouser", "password", SmsTextingAPI::JSON, "https://app.grouptexting.com");

say 'Get contacts';
$response =  $sms->getAll(SmsTextingAPI::CONTACT, 
    'source'        => 'upload',
    'optout'        => 'false',
    'group'         => 'Honey Lovers',
    'sortBy'        => 'PhoneNumber',
    'sortDir'       => 'asc',
    'itemsPerPage'  => '10',
    'page'          => '3');
say Dumper($response);


say 'Create contact';
$response = $sms->put(SmsTextingAPI::CONTACT,
    'PhoneNumber' => '2123456945',
    'FirstName'   => 'Piglet',
    'LastName'    => 'P.',
    'Email'       => '[email protected]',
    'Note'        => 'It is hard to be brave, when you are only a Very Small Animal.',
    'Groups'   => ['Friends', 'Neighbors']);
say Dumper($response);


say 'Get contact';
$contactId = $response->{Entry}->{ID};
$response =  $sms->get(SmsTextingAPI::CONTACT, $contactId);
say Dumper($response);


say 'Update contact';
$contact = $response->{Entry};
$contact->{'LastName'} = 'test';
$response = $sms->put(SmsTextingAPI::CONTACT, %$contact);
say Dumper($response);


say 'Delete contact';
$response =  $sms->delete(SmsTextingAPI::CONTACT, $contactId);
say Dumper($response);


say 'Second delete. try to get error';
$response =  $sms->delete(SmsTextingAPI::CONTACT, $contactId);
say Dumper($response);

                     

Groups

Groups

When working with Groups you can perform five actions: Post (Add New Group), Put (Update/Edit A Group), Delete (Delete A Group), Get (Get Group By ID), Index (Get All Groups). The code samples below use shared libraries:
· SMSTextingAPI.pm
· SmsTextingJsonDecoder.pm
· SmsTextingXmlDecoder.pm
You can download them, along with the code samples here: PerlLib.zip.

Code Samples

Perl - XML
#!/usr/bin/perl

use warnings;
use strict;
use SmsTextingAPI;
use Data::Dumper;
use feature qw(say);

say 'XML encoding.';
my $sms = new SmsTextingAPI("demouser", "password", SmsTextingAPI::XML, "https://app.grouptexting.com");

say 'Get groups';
my $response =  $sms->getAll(SmsTextingAPI::GROUP, 'sortBy' => 'Name');
say Dumper($response);


say 'Create group';
$response = $sms->put(SmsTextingAPI::GROUP,
    'Name'        => 'Tubby Bears',
    'Note'        => 'A bear, however hard he tries, grows tubby without exercise');
say Dumper($response);


say 'Get group';
my $groupId = $response->{Entry}->{ID};
$response =  $sms->get(SmsTextingAPI::GROUP, $groupId);
say Dumper($response);


say 'Update group';
my $group = $response->{Entry};
$group->{'Note'} = 'test';
$response = $sms->put(SmsTextingAPI::GROUP, %$group);
say Dumper($response);


say 'Delete group';
$response =  $sms->delete(SmsTextingAPI::GROUP, $groupId);
say Dumper($response);


say 'Second delete. try to get error';
$response =  $sms->delete(SmsTextingAPI::GROUP, $groupId);
say Dumper($response);

Perl - JSON
#!/usr/bin/perl

use warnings;
use strict;
use SmsTextingAPI;
use Data::Dumper;
use feature qw(say);


say 'JSON encoding.';
$sms = new SmsTextingAPI("demouser", "password", SmsTextingAPI::JSON, "https://app.grouptexting.com");

say 'Get groups';
$response =  $sms->getAll(SmsTextingAPI::GROUP, 'sortBy' => 'Name');
say Dumper($response);


say 'Create group';
$response = $sms->put(SmsTextingAPI::GROUP,
    'Name'        => 'Tubby Bears',
    'Note'        => 'A bear, however hard he tries, grows tubby without exercise');
say Dumper($response);


say 'Get group';
$groupId = $response->{Entry}->{ID};
$response =  $sms->get(SmsTextingAPI::GROUP, $groupId);
say Dumper($response);


say 'Update group';
$group = $response->{Entry};
$group->{'Note'} = 'test';
$response = $sms->put(SmsTextingAPI::GROUP, %$group);
say Dumper($response);


say 'Delete group';
$response =  $sms->delete(SmsTextingAPI::GROUP, $groupId);
say Dumper($response);


say 'Second delete. try to get error';
$response =  $sms->delete(SmsTextingAPI::GROUP, $groupId);
say Dumper($response);

No contracts, no setup fees, no kidding.


GroupTexting has partnered with EZ Texting to power its mass texting platform.
Signing up for GroupTexting will automatically create an EZ Texting account.


Get Started