PHP Library v2

View Repo

The Flowroute PHP Library v2 provides methods for interacting with Messages v2 of the Flowroute API.

Topics

Requirements




Installation

First, open a terminal window and clone the PHP Library v2.

git clone https://github.com/flowroute/flowroute-messaging-php.git 

            

Switch to the newly-created flowroute-messaging-php directory.

Download Composer in the same directory. PHP Library v2 comes with a composer.json listing the project dependencies and other metadata. Run the following:

php composer.phar install

            

Usage

In Flowroute's approach to building the Messaging (v2) API wrapper, HTTP requests are handled by the APIController, which contains the functions used to perform tasks with the PHP library.

APIController

The following shows how you can instantiate the Controllers and import the Models:

#Require Flowroute Messaging
<?php
 
   require_once('vendor/autoload.php');
   
   #Instantiate the Controllers
   use FlowrouteMessagingLib\Controllers\MessagesController;
   use FlowrouteMessagingLib\Models\Message;

            

Credentials

In your PHP file, replace accessKey:secretKey with your API credentials from the Flowroute Manager.

#Pass your API credentials
$controller_name = new MessagesController('Access Key','Secret Key');

            

Methods

createMessage()

The method accepts the msg, to, from, and body parameters which you can learn more about in the API reference.

#Create and send the message
$mymessage = new Message('18444205700', '12062092844', 'Get some exercise!');
$response = $controller->createMessage($mymessage);

            
Example Response
(
[data] => stdClass Object
   (
       [id] => mdr1-6bdb954473d249308d43debd4735b493
   )

)

            
getMessageLookup()

The method accepts the record_id parameter which you can learn more about in the API reference.

#Get the MDR
$response = $controller->getMessageLookup('mdr1-6bdb954473d249308d43debd4735b493');

            
Example Response
(
   [data] => stdClass Object
     (
         [attributes] => stdClass Object
            (
                [body] => Get some exercise!
                [direction] => outbound
                [timestamp] => 2016-05-20T17:07:46.322587+00:00
                [amount_nanodollars] => 4000000
                [from] => 12062092844
                [message_encoding] => 0
                [has_mms] =>
                [to] => 18444205700
                [amount_display] => $0.0040
                [callback_url] =>
                [message_type] => long-code
            )

        [type] => message
        [id] => mdr1-6bdb954473d249308d43debd4735b493
    )
)

            

Errors

In the PHP Library v2, the error handling produces the following example error object:

Example Error
--Purchase a Phone Number
Unirest\Response Object
(
    [code] => 422
    [raw_body] => {"error": "Business Logic Error: The TN is not available for purchase."}
    [body] => stdClass Object
        (
            [error] => Business Logic Error: The TN is not available for purchase.
        )

    [headers] => Array
        (
            [0] => HTTP/1.1 422 Unknown Status
            [Content-Type] => application/json
            [Date] => Thu, 27 Apr 2017 00:02:45 GMT
            [Server] => nginx
            [Content-Length] => 72
            [Connection] => keep-alive
        )

)

        

©2004 - 2024 BCM One. All right reserved. Legal | Privacy Policy | Blog | News | Contact