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 & PHP - Working Sandbox app code not working with graduated app
Tags: rest api, sending sms
Aug 14, 2023 at 7:03am   •   2 replies  •  0 likes
IWD

Hello All,

New to RingCentral development, but I created an app with an SMS endpoint (send SMS only) and built some code to get it working in the sandbox. Code works perfectly using the Sandbox credentials/client/server info. The app was then graduated, so I updated the following to the graduated app's credentials/info:

$client_id = 'production_appclientid'; //Removed for security
$client_secret = 'production_appclientsecret'; //Removed for security
$server_url = 'https://platform.ringcentral.com';
$rc_jwt = 'production_jwt_key'; //Removed for security


Having changed only the above 4 lines of code, the app is now failing at the highlighted line below:

function send_sms($fromNumber){
  global $platform, $RECIPIENT;
  try {
    $requestBody = array(
       'from' => array ('phoneNumber' => $fromNumber),
       'to' => array( array('phoneNumber' => $RECIPIENT) 
       'text' => 'test'
    );
    $endpoint = "/account/~/extension/~/sms";
    $resp = $platform->post($endpoint, $requestBody);
    $jsonObj = $resp->json();
    print("SMS sent. Message id: " . $jsonObj->id . PHP_EOL);
    check_message_status($jsonObj->id);
  } catch (\RingCentral\SDK\Http\ApiException $e) {
    exit("Error message: " . $e->message . PHP_EOL);
  }
}

I still have the Sandbox Environment active, do I need to suspend that? The Production Environment Status is "Active", and I'm able to see the requests I'm submitting are generating errors via the analytics panel.


When I view the Production End Points analytics, I see the errors are all to the endpoint "1/account/*/extension/*/sms". Every request to that endpoint in the Production Environment results in an error 403 or 400. Do I need to enable another endpoint for my app?


Any help/suggestions appreciated.

on Aug 14, 2023 at 8:07am   •  0 likes

Did you also call this function to detect the user's phone numbers and if the "from" phone number is SMS enabled?

/*
  Read phone number(s) that belongs to the authenticated user and detect if a phone number
  has the SMS capability
*/
function read_extension_phone_number_detect_sms_feature(){
  global $platform;
  $endpoint = "/restapi/v1.0/account/~/extension/~/phone-number";
  $resp = $platform->get($endpoint);
  $jsonObj = $resp->json();
  foreach ($resp->json()->records as $record){
    foreach ($record->features as $feature){
      if ($feature == "SmsSender"){
        // If a user has multiple phone numbers, check and decide which number
        // to be used for sending SMS message.
        return send_sms($record->phoneNumber);
      }
    }
  }
  if (count($jsonObj->records) == 0){
    exit("This user does not own a phone number!");
  }else{
    exit("None of this user's phone number(s) has the SMS capability!");
  }
}
on Aug 15, 2023 at 6:11am   •  0 likes

Thank you for your reply. I forgot to mention that in my code I wasn't calling this function, instead calling send_sms directly and specifying the $fromNumber programmatically, such as:

send_sms('18005551212');


I've updated my code to call this function instead of send_sms, then call send_sms from inside this function exactly as you've shown:

return send_sms($record->phoneNumber);


The code now fails at the highlighted line:

function read_extension_phone_number_detect_sms_feature(){
    global $platform;
    $endpoint = "/restapi/v1.0/account/~/extension/~/phone-number";
    $resp = $platform->get($endpoint);
    $jsonObj = $resp->json();
    foreach ($resp->json()->records as $record){
    foreach ($record->features as $feature){
        if ($feature == "SmsSender"){
            return send_sms($record->phoneNumber);
        }
    }
    }
    if (count($jsonObj->records) == 0){
        exit("This user does not own a phone number!");
    } else {
    exit("None of this user's phone number(s) has the SMS capability!");
    }
}

Here is the truncated error message. It appears to be a permissions issue?

Expected HTTP Error: Client error: `GET https://platform.ringcentral.com/restapi/v1.0/account/~/extension/~/phone-number` resulted in a `403 Forbidden` response: { "errorCode" : "InsufficientPermissions", "message" : "In order to call this API endpoint, application needs to hav (truncated...)

on Aug 15, 2023 at 8:36am   •  0 likes

Add the "Read Accounts" app scope to the app and try again. This is documented in the developer guide.

on Aug 15, 2023 at 11:40am   •  0 likes

I already have both of the two scopes required that were listed here when you click "Show detailed instructions". Do I need to add another scope as well?

app-scope.png

on Aug 15, 2023 at 11:58am   •  0 likes

Then it must be a mistake in the JWT token. 2 options to get help.

1. Submit a dev support ticket here. Or

2. Let me know the app client id and the user name (or extension id) who owns that JWT token

on Aug 15, 2023 at 1:01pm   •  0 likes

Thank you for your help.

Regarding the username/extension Id, do you mean my RingCentral Developer login? My apologies, I'm not 100% sure I know what you're looking for. I can also provide you with the email I used to regsiter? In my user profile it also says I'm extension 200.

I just finished a meeting, but I'll be monitoring this chat the rest of the afternoon and should reply promptly.

on Aug 15, 2023 at 2:41pm   •  0 likes

The user "Matt Puhl" does not have a phone nor a direct phone number so that user cannot send any text message.

I use the JWT token generated for the app "TTECH JET v3 - Production" and it works well. I could call the API to read extension phone number successfully. It's just there is no number from that user.

screen-shot-2023-08-15-at-23759-pm.png

on Aug 15, 2023 at 2:50pm   •  0 likes

@Phong Vu Thank you again for your help.

So the developer account's user must also be licensed in RC and assigned a phone number, does that sound right? I don't want take up all your time, is there any documentation that explains this? I did try to create a support ticket earlier, but got the attached error message.

I'm guessing I just need to talk to management about purchasing a license for my user account - is that what you'd recommend?

I didn't create the RC account, I primarily handle the company's IT systems, but I do see in RC Company Setup > User Management that, as you said, I have no number assigned and that my license type is "Video".


support-err.png

on Aug 15, 2023 at 3:32pm   •  0 likes

You wrote that your code is working well in sandbox account and now you graduate the app and run it in your production.

A user in your sandbox is not the same as a user in your production!

So if you run the app in the production, here is what you need to have:

Production app client id

Production app client secret

Production server https://platform.ringcentral.com

Production user: A user under your production

on Aug 15, 2023 at 4:02pm   •  0 likes

I appreciate that, but did you see my last comment? Are you saying my RingCentral account requires a license and phone #? I think that's what you're saying but was hoping for clarification. I understand a Sandbox user is not a Production user, but I wasn't sure what the best next step was.

on Aug 15, 2023 at 11:57am   •  0 likes

Ok, I removed and then re-added both of the scopes, saving the app each time. Then I waited 10 minutes and re-tried my code (I made no code changes). Now I get this error:

None of this user's phone number(s) has the SMS capability!

You mentioned in your initial comment that I should confirm this # has SMS enabled. We use our company # to send SMS via RC, but is there something else I need to do? I am searching in the developer guide but haven't found anything yet.


1 Answer
answered on Aug 15, 2023 at 4:37pm  

Your user extension does not need to have a license and phone. But it does need a phone number. You can purchase a phone number and assign to the user as a direct number then that user can send text message from his own number.


 0
on Aug 15, 2023 at 4:44pm   •  0 likes

Thank you. I appreciate all your help.



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