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
I set my all ring central credential with proper settings. But API throw error."Unable to authenticate to platform. Check credentials." I atteched my code and errors . Please check. We are in Production But cannot do single SMS through Production
Tags: oauth
Aug 7, 2023 at 8:48am   •   2 replies  •  0 likes
sky mikesell

I am facing error

==================================

Exception: Response has unsuccessful status in

/var/www/html/api/public_html/vendor/ringcentral/ringcentral-php/src/Http/Client.php:44

Stack trace:

#0 /var/www/html/api/public_html/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(310):

RingCentral\SDK\Http\Client->send(Object(GuzzleHttp\Psr7\Request))

#1 /var/www/html/api/public_html/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(434):

RingCentral\SDK\Platform\Platform->sendRequest(Object(GuzzleHttp\Psr7\Request), Array)

#2 /var/www/html/api/public_html/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(212):

RingCentral\SDK\Platform\Platform->requestToken('/restapi/oauth/...', Array)

#3 /var/www/html/api/public_html/sendSMS.php(38): RingCentral\SDK\Platform\Platform->login(Array)

#4 {main}


Next RingCentral\SDK\Http\ApiException: Unauthorized for this grant type in

/var/www/html/api/public_html/vendor/ringcentral/ringcentral-php/src/Http/Client.php:52

Stack trace:

#0 /var/www/html/api/public_html/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(310):

RingCentral\SDK\Http\Client->send(Object(GuzzleHttp\Psr7\Request))

#1 /var/www/html/api/public_html/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(434):

RingCentral\SDK\Platform\Platform->sendRequest(Object(GuzzleHttp\Psr7\Request), Array)

#2 /var/www/html/api/public_html/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(212):

RingCentral\SDK\Platform\Platform->requestToken('/restapi/oauth/...', Array)

#3 /var/www/html/api/public_html/sendSMS.php(38): RingCentral\SDK\Platform\Platform->login(Array)

#4 {main}Unable to authenticate to platform. Check credentials.



==========

My Code

<?php
//Header config
require __DIR__ . '/header.php';
/**Db connect */
require __DIR__ . '/dbConnect.php';
/**Ringcentral vendor config */
require __DIR__ . '/vendor/autoload.php';


//fetch all keys from database
//$query = 'SELECT * FROM public."Settings"';
//$result = pg_query($db, $query);
//while ($row = pg_fetch_assoc($result)) {
  
  
  $clientId = 'Xis4z9ojiqff8kozXxEFcQ';
  $clientSecret = '48TxqwJG...';
  $jwtToken = 'eyJraWQiOiI4...';
  $fromNumber = '+1704626XXX';
//}


$serverUrl = 'https://platform.ringcentral.com';


//$jsonValue = $_GET['finalJson'];
//$jsonValue = json_decode($jsonValue);


//receipient number
$receipientNo = '+1480409XXX';


// sms content
$message = 'Hello Sky';


# Instantiate the SDK and get the platform instance
$rcsdk = new RingCentral\SDK\SDK( $clientId,
$clientSecret,
$serverUrl );
$platform = $rcsdk->platform();


// Authenticate a user using a personal JWT token
try {
  
  
  $platform->login( [ "jwt" => $jwtToken ] );
  send_sms($fromNumber);
} catch (\RingCentral\SDK\Http\ApiException $e) {
  
  
  echo $e;
  exit("Unable to authenticate to platform. Check credentials. ");
}


/*
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!");
  }
}

/*
Send a text message from a user own phone number to a recipient number
*/
function send_sms($FROM_NUMBER){
  
  
  global $platform, $receipientNo, $message;
  try {
  
  
    $requestBody = array(
      'from' => array ('phoneNumber' => $FROM_NUMBER),
      'to' => array( array('phoneNumber' => $receipientNo) ),
      // To send group messaging, add more (max 10 recipients) 'phoneNumber' object. E.g.
    /*
    'to' => array(
    array('phoneNumber' => $receipientNo),
      array('phoneNumber' => 'Recipient-Phone-Number')
    ),
    */
    'text' => $message
    );
    $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);
  }
}

/*
Check the sending message status until it's out of the queued status
*/
function check_message_status($messageId){
  
  
  global $platform;
  try {
  
  
    $endpoint = "/restapi/v1.0/account/~/extension/~/message-store/".$messageId;
    $resp = $platform->get($endpoint);
    $jsonObj = $resp->json();
    print("Message status: " . $jsonObj->messageStatus . PHP_EOL);
    if ($jsonObj->messageStatus == "Queued"){
  
  
      sleep(2);
      check_message_status($jsonObj->id);
    }
  } catch (\RingCentral\SDK\Http\ApiException $e) {
  
  
    exit("Error message: " . $e->message . PHP_EOL);
  }
}
?>


===========

on Aug 7, 2023 at 9:27am   •  0 likes

Seriously? You posted the entire app client id, app client secret and JWT token on your company production account on a public forum?

I hope that other people did not see or copy them before I deleted them for you.

1 Answer
answered on Aug 7, 2023 at 11:56am  

Make sure that you upgrade the latest RingCentral PHP SDK which support JWT token. I doubt that you are still using the old SDK and that is way your error message showed authentication failed.

You app also does not have the Read Accounts app scope which is needed for reading the extension phone number. I added the missing scope to the app and use your credentials to send a test SMS message using the code successfully.

You should receive a text message to your direct number with the following message:

"RC Dev community: Test sent from your main company number to your direct number"

Just run your code again.

Please take my comment seriously as posting your account sensitive info on public site could lead to security issue with your production account.


 0



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