Mobile Sasa


How To Kick Off

Log into your mobilesasa account and navigate to the Developer section.

Create an App.

Upon app creation, you will be provided with your apps client id and client secret.

The client id and client secret will be used whenever you want to generate an access token for your app api connection.

In the Developer section, there is the api_key that is sent along with the access token when sending an sms. You should be able to see a page similar to this in the picture below

API IMAGE



Mobile Sasa Request Parameters (kindly note the case)

senderID - senderID associated with your account

phone - the phone number message should be sent.

message - the message to the sent.

api_key - the api key for your account



STEP ONE - Generating Access Tokens


            curl -X POST \
              https://account.mobilesasa.com/oauth/token \
              -H 'Content-Type: application/json' \
              -d '{
              "grant_type":"client_credentials",
              "client_secret":"<client_secret>",
              "client_id":"<client_id>"
            }'
            


STEP TWO ALTERBATIVE 1 - sending sms over POST


            curl -X POST \
            https://account.mobilesasa.com/api/post-sms \
            -H 'Accept: application/json' \
            -H 'Authorization: Bearer ' \
            -H 'cache-control: no-cache' \
            -d '{
                  "senderID":"<senderID>",
                  "phone":"<phone>",
                  "message":"<message>",
                  "api_key":"<api-key>"
            }'
            


STEP TWO ALTERBATIVE 2 - sending sms over GET


            curl -X GET \
            'https://account.mobilesasa.com/api/get-sms?senderID=<senderID>&phone=<phone>&message=<message>&api_key=<api-key>' \
            -H 'Accept: application/json' \
            -H 'Authorization: Bearer <access-token>' \
            -H 'X-Requested-With: XMLHttpRequest' \
            -H 'cache-control: no-cache'
            


EXAMPLE USING PHP

The following uses PHP programming language


            <?php
            /**
            * Request for access token
            */
            function generateAccessToken() {
              $postData = array(
                    'client_id' => '5b021f00-e350-11e8-8483-05aaehfein467sd',
                    'client_secret' => '2CSAm9JDMCkrAC94DrJFGxsjxusER61UnA0fyPmRCA',
                    'grant_type' => 'client_credentials'
                );

                $requestBody = json_encode($postData);

                 // Setup cURL
                $ch = curl_init('https://account.mobilesasa.com/oauth/token');
                curl_setopt_array($ch, array(
                    CURLOPT_POST => TRUE,
                    CURLOPT_RETURNTRANSFER => TRUE,
                    CURLOPT_HTTPHEADER => array(
                        'Content-Type: application/json'
                    ),
                    CURLOPT_POSTFIELDS => $requestBody
                ));

                // Send the request
                $response = curl_exec($ch);

                // var_dump($response);
                return $response;
            }

            /**
            * Send sms over POST
            */
            function sendPostSms($token, $senderID, $phone, $message, $api_key)
            {
              $accessToken = "Bearer ".$token;

                    $postData = array(
                            'senderID' => $senderID,
                            'phone' => $phone,
                            'message' => $message,
                            'api_key' => $api_key
                        );

                        $requestBody = json_encode($postData);

                        // Setup cURL
                        $ch = curl_init('https://account.mobilesasa.com/api/post-sms');
                        curl_setopt_array($ch, array(
                            CURLOPT_POST => TRUE,
                            CURLOPT_RETURNTRANSFER => TRUE,
                            CURLOPT_HTTPHEADER => array(
                                'Accept: application/json',
                                'Authorization: '.$accessToken
                            ),
                            CURLOPT_POSTFIELDS => $requestBody
                        ));

                        // Send the request
                        $response = curl_exec($ch);

                        // var_dump($response);
                        return $response;
            }

            /**
            * Send SMS over GET
            */
            function sendGetSms($token, $senderID, $phone, $message, $api_key)
            {
              $accessToken = "Bearer ".$token;

                    $postData = array(
                            'senderID' => $senderID,
                            'phone' => $phone,
                            'message' => $message,
                            'api_key' => $api_key
                        );

                        // Setup cURL
                        $ch = curl_init("https://account.mobilesasa.com/api/get-sms?senderID=$senderID&phone=$phone&message=$message&api_key=$api_key");
                        curl_setopt_array($ch, array(
                            CURLOPT_POST => TRUE,
                            CURLOPT_RETURNTRANSFER => TRUE,
                            CURLOPT_HTTPHEADER => array(
                                'Accept: application/json',
                                'Authorization: '.$accessToken
                            ),
                            CURLOPT_CUSTOMREQUEST => 'GET'
                        ));

                        // Send the request
                        $response = curl_exec($ch);

                        // var_dump($response);
                        return $response;
            }


            //get access token
            $token = json_decode(generateAccessToken(), true)['access_token'];

            //send over GET and dump response/decode
            var_dump(sendGetSms($token, 'MOBILESASA', '070xxxxxx, 'Message body', 'api-key'));

            //send over POST and dump response/decode
            var_dump(sendPostSms($token, 'MOBILESASA', '070xxxxxx, 'Message body', 'api-key'));