News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
SMS API in PHP without needing to install via composer
Tags: sms and text messaging
Jan 8, 2023 at 6:51pm   •   1 replies  •  0 likes
Alex Gold

Hey all!

I need to get hooked up to the SMS API (via PHP), but step one is installing a SDK via composer.

I'm on shared hosting and the host says I can't do that.

Is there a way to access and use the API solely over cURL or a REST API of some kind? (Especially with an easy to use example in PHP where I could plug in my RingCentral keys, my number, and shoot out a text message to someone?)

Thanks!
Alex

1 Answer
answered on Jan 9, 2023 at 8:13am  

I built a light PHP library to authenticate and access RingCentral platform and it is available in my GitHub repos listed below. The libraries also require using the composer to install the "vlucas/phpdotenv" dependency. But you can remove it and don't use the environment.

JWT lib

Code flow lib


 1
on Jan 9, 2023 at 9:49am   •  0 likes

I appreciate the response! I'm very out of my element in terms of server stuff (I really just know straight, basic PHP); so I'm not even sure how to remove that dependency.

If I can just get a plain PHP example that connects via cURL or a REST API for one function (sending a text), then I should be able to adapt that to the others (basically I just need to be able to send texts and read old texts; maybe see old calls as well).

I'm even happy to pay someone to write that simple script as it'd take me forever to derive it from the more complicated "full-feature" packages.

on Jan 9, 2023 at 10:41am   •  0 likes

Basically, you open the ringcentral.php file and change the code as follows:

Remove the dependency code

/*
require_once('vendor/autoload.php');

$dotenv = Dotenv\Dotenv::createMutable(__DIR__, '.env');
$dotenv->load();


$env_file = "./environment/";
if ($_ENV['ENVIRONMENT'] == "sandbox"){
  $env_file .= ".env-sandbox";
}else{
  $env_file .= ".env-production";
}

$dotenv = Dotenv\Dotenv::createMutable(__DIR__, $env_file);
$dotenv->load();
*/

Replace these params with the actual values

//$url = $_ENV["RC_SERVER_URL"] . "/restapi/oauth/token";
$url = "https://platform.devtest.ringcentral.com/restapi/oauth/token"; // sandbox environment
$url = "https://platform.ringcentral.com/restapi/oauth/token"; // production environment

//$basic = $_ENV["RC_CLIENT_ID"] .":". $_ENV["RC_CLIENT_SECRET"];
$basic = "YourAppClientId:YouAppClientSecret";

$body = http_build_query(array (
              'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
              'assertion' => "Your  JWT token"
            ));


It's hard for me to help you further if you know just a little about PHP. You may need to know a lot more about PHP programming to build an application.

on Jan 9, 2023 at 12:20pm   •  0 likes

Yeah, I was hoping to side step building an entire application if I really just needed one or two simple features - like with Stripe, I was able to build it into a simple PHP function to charge a card via cURL and then adapt as needed from there and it went well (and then I added other features as needed from there).

I might just hop on Freelancer and see if someone wants $10 or $20 to just build a single PHP function where I just put in my authorization details, a phone number to text to, and a message, and it works. I can adapt it from there, but it just takes a lot more time to strip a more fully featured solution down to the simple bones of what I need.

Assuming that's even possible?

on Jan 11, 2023 at 12:16am   •  0 likes

Hey Alex,
This is definitely doable. The authentication model between Stripe and RingCentral are different as Stripe is org based (client and secret) and RingCentral is user based (client, secret, and then user JWT or credentials). This makes the RingCentral auth a little bit more complicated as it requires multiple API calls to authenticate, but still doable in a single script using basic cURL requests.

Depending on how many times you're calling the script, you may have to store the bearer token server-side/ in memory to avoid authentication rate limiting. If you call the script once to send numerous SMS, this shouldn't be an issue - but either way it shouldn't add too much complexity depending on your server/ cloud setup.

Once authenticated with the bearer token, very straight forward to send SMS (just another cURL request). Again the only risk here is if you end up sending messages too quickly (in which case I would recommend using our High Volume SMS solution that automatically queues the messages for you).

So with all that said, if you find someone who is already familiar with RingCentral's APIs or using OAuth/JWT tokens/ bearer tokens they should be able to build this pretty quickly without the need to pull in the RingCentral PHP SDK/ third party code libraries. I'll also check to see if I have some sample code that I can add here.

As a side note, Composer has become pretty popular for PHP. While your host may not support, if you're able to install PHP on your computer you can run `php composer.phar` to install the files locally, and then you can upload to your shared host.

Hope that helps,
Mike

on Jan 11, 2023 at 8:20pm   •  1 likes

Hey Mike! Here's the output I'm getting. It looks like everything is set up correctly but I don't see any SMS logs in the sandbox admin side (I'm redacting a few details in the post).

I see the messageStatus is 'queued' (not 'sent' or something similar), so not sure if that's normal or a sign of an issue?

Thanks!
Alex


Array
(
    [uri] => https://platform.devtest.ringcentral.com/restapi/v1.0/account/766906005/extension/766906005/message-store/12388377005
    [id] => 12388377005
    [to] => Array
        (
            [0] => Array
                (
                    [phoneNumber] => +[REDACTED]
                )

        )

    [from] => Array
        (
            [phoneNumber] => +[REDACTED Sandbox nmber]
            [name] => [REDACTED]
            [location] => New York City, NY
        )

    [type] => SMS
    [creationTime] => 2023-01-12T04:13:09.000Z
    [readStatus] => Read
    [priority] => Normal
    [attachments] => Array
        (
            [0] => Array
                (
                    [id] => 12388377005
                    [uri] => https://platform.devtest.ringcentral.com/restapi/v1.0/account/766906005/extension/766906005/message-store/12388377005/content/12388377005
                    [type] => Text
                    [contentType] => text/plain
                )

        )

    [direction] => Outbound
    [availability] => Alive
    [subject] => Test SMS using a RingCentral Developer account - testing SMS
    [messageStatus] => Queued
    [smsSendingAttemptsCount] => 1
    [conversationId] => 4708791979630659733
    [conversation] => Array
        (
            [id] => 4708791979630659733
            [uri] => https://platform.devtest.ringcentral.com/restapi/v1.0/conversation/4708791979630659733
        )

    [lastModifiedTime] => 2023-01-12T04:13:19.920Z
)
on Jan 11, 2023 at 9:08pm   •  0 likes

If you check the analytics in the Developer Portal, it may take up to 15 minutes for the request to show up (I know we're working on getting it closer to real-time, but not sure if that's been deployed yet).

As for status, you should be good. Queued means that it is pending being sent, if you pull the status for it again (using message store) it should say sent, delivered, or even read.

Let me know if you run into any issues, but so looks good to me.

on Jan 12, 2023 at 8:18am   •  0 likes

https://service.devtest.ringcentral.com/application/sms

Is that the right page to see the SMS log? It's still totally blank for me (I sent the test texts 10 or 15 hours ago so it's definitely not a 15 minutes delay at least ).


I got the message-store set up and I do see the previous messages but the messageStatus is "SendingFailed":

Maybe as it's attempting to send to a real number (my personal number) on the sandbox side? (Is there a way to make a seperate test number inside the sandbox mode to test with that?)

 [uri] => https://platform.devtest.ringcentral.com/restapi/v1.0/account/766906005/extension/766906005/message-store/12393953005
                    [id] => 12393953005
                    [extensionId] => 766906005
                    [to] => Array
                        (
                            [0] => Array
                                (
                                    [phoneNumber] => [REDACTED]
                                )

                        )

                    [from] => Array
                        (
                            [phoneNumber] => +[REDACTED]
                            [name] => Alex Gold
                            [location] => New York City, NY
                        )

                    [type] => SMS
                    [creationTime] => 2023-01-12T15:02:38.000Z
                    [readStatus] => Read
                    [priority] => Normal
                    [attachments] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 12393953005
                                    [uri] => https://platform.devtest.ringcentral.com/restapi/v1.0/account/766906005/extension/766906005/message-store/12393953005/content/12393953005
                                    [type] => Text
                                    [contentType] => text/plain
                                )

                        )

                    [direction] => Outbound
                    [availability] => Alive
                    [subject] => Test SMS using a RingCentral Developer account - testing SMS
                    [messageStatus] => SendingFailed
                    [smsSendingAttemptsCount] => 3
                    [conversationId] => 4708791979630659733
                    [conversation] => Array
                        (
                            [id] => 4708791979630659733
                            [uri] => https://platform.devtest.ringcentral.com/restapi/v1.0/conversation/4708791979630659733
                        )

                    [lastModifiedTime] => 2023-01-12T15:18:17.949Z
on Jan 12, 2023 at 9:00am   •  0 likes

"Maybe as it's attempting to send to a real number (my personal number) on the sandbox side? (Is there a way to make a seperate test number inside the sandbox mode to test with that?)"

Login your sandbox account admin portal, add a new user and add a new direct number for the new user. Then you can test sending text messages between the users.

on Jan 12, 2023 at 9:08am   •  1 likes

Just did that and sent a text message between them - waiting to see the queue. I'll check back in a while. Got all the other API's I needed working so I assume this one would work in the live production - I'll request the production as soon as the error ones are old enough to get that success percent high enough to request it :).


on Jan 12, 2023 at 12:22pm   •  1 likes

Update: I got the live application approved and it's working just fine there with my live personal number. So whatever was being funky in the sandbox is working just fine now at least. Thanks so much!

on Jan 12, 2023 at 8:22am   •  0 likes

Ah, I was able to text INTO the sandbox from my live number and the read_message has it listed. So I just can't (currently) test sending from inside the sandbox. ButI I'll assume that code works as it seems to be, generally speaking.

on Jan 11, 2023 at 7:21pm   •  1 likes

Thanks! I hired someone one freelancer to whip up a one-page version and it appears to work in the sandbox at least (I need to apply for production, evidently).

I'll look into installing local, though, as I do have MAMP and could likely do that. Good to know!



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us