PHP code example of tooma / sms-api

1. Go to this page and download the library: Download tooma/sms-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tooma / sms-api example snippets


 $tooma->onSuccess(function($response,$pagination){
          // Logic when Login is successfull
          $apiKey = $response->data->token;

       })->onError(function($response)
       {
           // Logic on Error 
       })->login(['username'=>'YOUR_USERNAME_OR_EMAIL','password'=>'YOUR_PASSWORD']);

 

 $parcel=[
	   ['to'=>'+254XXXXXXXXX','message'=>'Greetings from Tooma'],
	   ......
	];
 $tooma->onSuccess(function($response,$pagination){
          // Logic sending is successfull

       })->onError(function($response)
       {
           // Logic on Error 
       })->sendSms($parcel);
  

 $parcel=[
	   ['to'=>'+254XXXXXXXXX','message'=>'Dear XXX Greetings from Tooma'],
	   ['to'=>'+254YYYYYYYYY','message'=>'Dear YYY Greetings from Tooma'],
	   ......
	];
 $tooma->onSuccess(function($response,$pagination){
          // Logic sending is successfull
        

       })->onError(function($response)
       {
           // Logic on Error 
       })->sendSms($parcel);
  

  $tooma->onSuccess(function($response,$pagination){
          $rows = $response->data;
          // save to db
          $pagination->getNext(); // call this to fetch the next page

       })->onError(function($response)
       {
           // Logic on Error 
       })->messageLogs();
   

  $tooma->onSuccess(function($response,$pagination){
          

       })->onError(function($response)
       {
           // Logic on Error 
       })->messageStatus(['message_id(s)']);
   

 $tooma->onSuccess(function($response,$pagination){
          // Logic sending is successfull
           echo "Your balance is $response->data->balance";

       })->onError(function($response)
       {
           // Logic on Error 
       })->balance();
 

  $csvPath = "path/to/your/csv.csv";

  $tooma->onSuccess(function($response,$pagination){
          // Logic sending is successfull
           echo "Your balance is $response->data->balance";

       })->onError(function($response)
       {
           // Logic on Error 
       })->withCsv($csvPath)
         ->withPhoneColumn('phone') //name of column with phone
         ->withTemplate('Dear :username_column_name your account balance is :balance_column_name')
         ->sendCsv();
 

 $data = [
   ['phone'=>'+254WWWWW','name'=>'','other_args'=>'args_val'];

 ];
 $tooma->onSuccess(function($response,$pagination){
          // Logic sending is successfull
           echo "Your balance is $response->data->balance";

       })->onError(function($response)
       {
           // Logic on Error 
       })->withParams(['args1'=>'val']) //extra parametaer
         ->withTemplate('Dear :name your account balance is :balance_column_name') //or you can pass a template id
         ->sendFromTemplate($data);
 

  $parcel=[
	   ['to'=>'+254XXXXXXXXX','message'=>'Greetings from Tooma'],
	   ......
	];
  $tooma->onSuccess(function($response,$pagination){
          // Logic sending is successfull
           echo "Your balance is $response->data->balance";

       })->onError(function($response)
       {
           // Logic on Error 
       })->schedule("FORMART")
         ->sendSms($parcel);