Fortytwo offers numerous ways for you to connect your applications to our Advanced Messaging Platform, allowing your systems to seamlessly communicate with your customers anywhere in the world.
For more information technical information go to our API Section »
To try out our IM/SMS Messaging system you have to Register for a FREE Test Account.
The SMS REST interface is an application hosted on a server that listens for HTTP requests containing SMS message data encoded in JSON. It processes the HTTP requests and their associated SMS message data and sends the required SMS messages for onward delivery. The SMS REST interface sends back a JSON response containing information about the submitted SMS messages such as the message identifiers of the sent SMS messages.
The SMS REST interface also includes a callback application which sends back delivery reports. The callback application achieves this by sending HTTP callback requests to your HTTP server (which must return an appropriate response) in order for delivery reports to be received. The figure below illustrates the architectural setup.
Use the method called sendSMS() to send a very simple SMS to a mobile phone.
Example File: /examples/send_sms.php
The parameters for this method are:
- #Send an SMS to one mobile phone number
- require_once('../src/fortytwo/FortytwoMessage.php');
- $message = new FortytwoMessage('INSERT_TOKEN_HERE');
- $return = $message->sendSMS('INSERT_MOBILE_HERE','INSERT_CONTENT_HERE');
- //Handle the Return
- var_dump($return);
Use the method called sendMultipleSMS() to send a very simple SMS to multiple mobile phone.
Example File: /examples/send_multiple_sms.php
The parameters for this method are:
- #Send SMS to Multiple Phone Numbers
- require_once('../src/fortytwo/FortytwoMessage.php');
- $message = new FortytwoMessage('INSERT_TOKEN_HERE');
- $arrayNumbers = array('INSERT_MOBILE_HERE','INSERT_MOBILE_HERE');
- $return = $message->sendMultipleSMS($arrayNumbers,'INSERT_CONTENT_HERE');
- //Handle the Return
- var_dump($return);
Use the method called sendComplexSMS() to send a very a complex SMS (used for customisations).
Example File: /examples/send_complex_sms.php
The parameters for this method are:
- #Send Complex SMS
- require_once('../src/fortytwo/FortytwoMessage.php');
- $message = new FortytwoMessage('INSERT_TOKEN_HERE');
- $message->setTTL(500);
- $destination1 = new Destination('INSERT_MOBILE_NUMBER_1');
- $destination2 = new Destination('INSERT_MOBILE_NUMBER_2');
- $destinationArray = array($destination1,$destination2);
- $SMSContent = new SMSContent('INSERT_CONTENT_HERE');
- $SMSContent->setSenderId('INSERT_SENDER_ID');
- $return = $message->sendComplexSMS($destinationArray,$SMSContent);
- //Handle the Return
- var_dump($return);
The IM REST interface is an application hosted on a server that listens for HTTP requests containing IM message data and/or SMS message data encoded in JSON. It processes the HTTP requests and their associated IM and/or SMS message data, performs some routing logic, and sends the required messages for onward delivery. The IM REST interface sends back a JSON response containing information about the submitted IM and/or SMS messages such as the message identifiers of the sent messages.
The IM REST interface allows undelivered IM messages to automatically fallback to the use of the SMS gateway if so desired.
The IM REST interface also includes a callback application which sends back delivery reports. The callback application achieves this by sending HTTP callback requests to your HTTP server (which must return an appropriate response) in order for delivery reports to be received. The figure below illustrates the architectural setup.
Use the method called sendIM() to send an Instant Message via VIBER to a mobile phone.
Example File: /examples/send_im.php
The parameters for this method are:
- #Send IM Message to one Phone Number
- require_once('../src/fortytwo/FortytwoMessage.php');
- $message = new FortytwoMessage('INSERT_TOKEN_HERE');
- $return = $message->sendIM('INSERT_MOBILE_HERE','INSERT_CONTENT_HERE');
- //Handle the Return
- var_dump($return);
Use the method called sendMultipleIM() to send Instant Messages via VIBER to a range of mobile phones.
Example File: /examples/send_multiple_im.php
The parameters for this method are:
- #Send IM Message to multiple Phone numbers
- require_once('../src/fortytwo/FortytwoMessage.php');
- $message = new FortytwoMessage('INSERT_TOKEN_HERE');
- $arrayNumbers = array('INSERT_MOBILE_HERE','INSERT_MOBILE_HERE');
- $return = $message->sendMultipleIM($arrayNumbers,'INSERT_CONTENT_HERE');
- //Handle the Return
- var_dump($return);
Use the method called sendComplexIM() to send a very a complex IM (used for customisations).
Example File: /examples/send_complex_im.php
The parameters for this method are:
- #Send Complex IM
- require_once('../src/fortytwo/FortytwoMessage.php');
- $message = new FortytwoMessage('INSERT_TOKEN_HERE');
- $destination1 = new Destination('INSERT_MOBILE_NUMBER_1');
- $destination2 = new Destination('INSERT_MOBILE_NUMBER_2');
- $destinationArray = array($destination1,$destination2);
- $imContent = new IMContent('INSERT_IM_CONTENT_HERE');
- $return = $message->sendComplexIM($destinationArray,$imContent);
- //Handle the Return
- var_dump($return);
The developer can opt to send the message via SMS (if cheaper) rather than via IM. (Prices can be checked from the prices page in the "FortyTwo IM Control Panel").
The Token generated can also be set to have the current "Message Plan" selected automatically by adjusting it in the Control Panel. The Message Plan routing can also be overriden with the $cheapestFirst parameter (If this is set to 'TRUE' and SMS is cheaper than IM, then SMS would be used)
In some cases, the destination mobile phone might not have the IM platform (e.g Viber) installed, in this case the developer can opt to do a fallback mechanism to send an SMS in case this happens. The IM message might fallback to SMS if
Use the method called sendInstantMessageOrSms() to send Instant Messages or SMS depending on the selected Message Plan.
Example File: /examples/send_im_or_sms.php
The parameters for this method are:
- #Send an Instant Message or SMS to one destination
- require_once('../src/fortytwo/FortytwoMessage.php');
- $message = new FortytwoMessage('INSERT_TOKEN_HERE');
- $return = $message->sendInstantMessageOrSMS('INSERT_MOBILE_HERE','INSERT_IM_CONTENT_HERE','INSERT_SMS_CONTENT_HERE');
- //Handle the Return
- var_dump($return);
Use the method called sendMultipleInstantMessageOrSms() to send multiple Instant Messages or SMS depending on the selected Message Plan.
Example File: /examples/send_multiple_im_or_sms.php
The parameters for this method are:
- #Send an Instant Message or SMS to multiple destinations
- require_once('../src/fortytwo/FortytwoMessage.php');
- $message = new FortytwoMessage('INSERT_TOKEN_HERE');
- $arrayNumbers = array('INSERT_MOBILE_HERE','INSERT_MOBILE_HERE');
- $return = $message->sendMultipleInstantMessageOrSMS($arrayNumbers,'INSERT_IM_CONTENT_HERE','INSERT_SMS_CONTENT_HERE');
- //Handle the Return
- var_dump($return);
Use the method called sendComplexInstantMessageOrSms() to send custom Instant Messages or SMS depending on the selected Message Plan.
Example File: /examples/send_complex_im_or_sms.php
The parameters for this method are:
- #Send Complex Instant Message or SMS (taking LOW_COST as a message plan)
- require_once('../src/fortytwo/FortytwoMessage.php');
- $message = new FortytwoMessage('INSERT_TOKEN_HERE');
- #Add multiple Destinations - Start
- $destination1 = new Destination('INSERT_MOBILE_HERE');
- $destination2 = new Destination('INSERT_MOBILE_HERE');
- $destinationArray = array($destination1,$destination2);
- #Add multiple Destinations - End
- $imContent = new IMContent('INSERT_IM_CONTENT');
- $SMSContent = new SMSContent('INSERT_SMS_CONTENT');
- $SMSContent->setSenderId('INSERT_SENDER_ID');
- $return = $message->sendComplexInstantMessageOrSMS($destinationArray,$imContent,$SMSContent,true);
- //Handle the Return
- var_dump($return);
Developers can also opt for building their own JSON Object and sending it to the REST API Server directly.
In the event that the developer wants to build his own JSON Object rather than using the simplified methods supplied above, the postData() method can be used.
Example File: /examples/json_post.php
The parameters for this method are:
- #Send a JSON Object to REST API Server
- #Check Documentation on how to generate a JSON Object
- require_once('src/fortytwo/FortytwoMessage.php');
- $messageObject = new FortytwoMessage('INSERT_TOKEN_HERE');
- $response = $messageObject->postData('{
- "destinations": [
- {
- "number": "INSERT_MOBILE_NUMBER"
- }
- ],
- "sms_content": {
- "message": "INSERT_SMS_CONTENT",
- "sender_id": "INSERT_SENDER_ID"
- }
- }');
- var_dump($response);
This PHP Library acts a bridge to Fortytwo REST API server, thus any data validation is handled through the REST API itself.
The request itself will return an JSON Object (String) with all the relevant information (e.g Invalid Token) and its up to the Developer on how they want to handle/display this information in their system.
If the response returned with HTTP Status Code set to "200", then the request was successful, any other status means that there was an error.
Read more about Responses »
If the request had validation errors the API will return a JSON object as shown below:
- {
- "api_job_id": "54a84753-492b-438a-9e08-15fad2057710",
- "result_info": {
- "status_code": 403,
- "description": "Forbidden: Validation error/s has/have occured, Reason/s: DestinationInfo has an invalid [number]
- value. Value [avc] does not match pattern [^[1-9][0-9]{6,14}$]. DestinationInfo fields were: MSISDN[number]:[avc];
- CUSTOM_ID[custom_id]:[null]; TEXT_PARAMS[params]:[null]"
- },
- "results": {}
- }
If the request was successful the API will return a JSON object as shown below:
- {
- "api_job_id":"6b6b843c-542225a-4118-8d6c-26ac61009efc",
- "result_info":{
- "status_code":200,
- "description":"Request successful (no errors occured and the message has been submitted)"
- },
- "results":{
- "35690556699":{
- "message_id":"14416294250660014003",
- "custom_id":""
- }
- }
- }