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
Resource Owner credentials are incomplete "Undefined index: username"
Tags: sdk
Jan 3, 2018 at 11:04am   •   6 replies  •  0 likes
bhagyashree-more

Hi Team

I want to send text.I try this code for sending sms:



<?php



require('vendor/autoload.php');


use RingCentral\SDK\SDK;



// Parse the .env file

$dotenv = new Dotenv\Dotenv(getcwd());

$dotenv->load();



try {



// Create SDK instance

$rcsdk = new SDK($_ENV['GLIP_APPKEY'], $_ENV['GLIP_APPSECRET'] , $_ENV['GLIP_SERVER'], 'Demo', '1.0.0');


// Create Platform instance

$platform = $rcsdk->platform();

/*

* Using the caching mechanism

*/

$cacheDir = __DIR__ . DIRECTORY_SEPARATOR . '_cache';

$file = $cacheDir . DIRECTORY_SEPARATOR . 'platform.json';


$cachedAuth = array();


if (file_exists($file)) {


$cachedAuth = json_decode(file_get_contents($file), true);

}


$platform->auth()->setData($cachedAuth);


// To login user

$rc=$platform->login($_ENV['username'],$_ENV['extension'],$_ENV['password']);


$apiResponse = $rcsdk->platform()->post('/account/~/extension/~/sms', array(

'from' => array('phoneNumber' => 'your-ringcentral-sms-number'),

'to' => array(

array('phoneNumber' => 'mobile-number'),

),

'text' => 'Test from PHP',

));

/*

* Setup Webhook Subscription

*/

$apiResponse = $platform->post('/subscription',array(

"eventFilters"=>array(

"/restapi/v1.0/glip/groups",

"/restapi/v1.0/glip/posts"

),

"deliveryMode"=>array(

"transportType"=> "WebHook",

"address"=>$_ENV['GLIP_WEBHOOK_URL']

)

));


print PHP_EOL . "Wohooo, your Bot is Registered now." . PHP_EOL;


} catch (Exception $e) {


print 'Webhook Setup Error: ' . $e->getMessage() . PHP_EOL;

}


after running this code I get this error:



Please tell me if i miss something in this.Also suggest docs for sending msg from local machine.



6 Answers
answered on Jan 4, 2018 at 6:04pm  
Are you trying to send an SMS from Glip using the Bot you have created above? For ex: by typing in the below command:



I have added the functionality to send sms in the webhook.php file as below:

$botman->hears('send sms to {number}', function (BotMan $bot, $query) {
    $bot->reply($query);
})->driver(GlipBotman::class);

So the Adapter listens to the message and parses the {number} and sends SMS. Kindly try the updated branch and provide us your feedback:
https://github.com/ringcentral/glip-botman/tree/bot-provisioner

Please note the changes in the .env file below:
https://github.com/ringcentral/glip-botman/tree/bot-provisioner#configure-your-bot

If there is any concern, please feel free to open issue in the Github Repository below:
https://github.com/ringcentral/glip-botman/issues

Hope this information helps!


 0
answered on Jan 4, 2018 at 12:03pm  
OK sir. I try that code. Thanks for help.
I want more help. Can you please help to resolve?
I am successfully registered my bot.Now I want to add API in that like (SMS,Meeting,Call,).
  1. I try first SMS API as above mention which I won't be able to implement in my local machine file.
  2. I try this same from UI in that when I run post and get method for SMS then it's working. 
  3. Can you please tell me how to add this code in my local machine code(php).
  4. Where we can see the send msg?
  5. I search every where but i won't be able to find right option to see my send message in my inbox ?
Please guide me..





 0
answered on Jan 4, 2018 at 11:39am  
I agree with Phong. 

Also, please note that if your application is of the type " Server/Bot" you cannot authorize using the Password Flow 

Since your app was authorized using the OAuth2.0, the adapter stores the token in a folder named _cache which you could re-use to make API calls. 

Make sure to delete the below line inside index.php and re-try:
$rc=$platform->login($_ENV['username'],$_ENV['extension'],$_ENV['password']);


 0
answered on Jan 4, 2018 at 11:04am  
Can you check or post the content (w/o values, just the key) of the env file. It looks like your key in the env file does not match with the key "username" in your index.php. Looks like you copied/pasted the code from different example and the env was taken from the botman example which is GLIP_USERNAME not username.

I cannot say much w/o seeing some of the code though.

+ Phong

 1
answered on Jan 3, 2018 at 11:38pm  
Yes, we are trying to send SMS using a Bot. We already have referred demo from Official PHP SDK to send SMS and we got error shown in screenshot attached in previous thread. Could you provide your insight on error ? Also let us know if we are missing something.

 0
answered on Jan 3, 2018 at 12:14pm  
Are you trying to send SMS using a Bot? The code in index.php is used to set up a subscription via webhook for the bot. I am not very sure about what you are trying to achieve.

However, we have a demo in our Official PHP SDK to send SMS. Kindly go on and read below to know more:

API Documentation: 
https://developer.ringcentral.com/api-docs/latest/index.html#!#RefSMSMessages.html

SMS Demo:
https://github.com/ringcentral/ringcentral-php#send-sms---make-post-request

Hope this helps!



 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