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
CS0103 exception when trying to send SMS
Tags: sms and text messaging
Jan 7, 2021 at 6:49am   •   5 replies  •  0 likes
Rick Smith

Trying this code to send SMS in C# it is throwing a CS0103 at this point:

var response = await extension.Sms().Post(requestBody); //name extension does not exist in current context.


The full code
public async void sendSms()
{
RestClient rc;
rc = new RestClient("id, "clientsecret", "https://platform.devtest.ringcentral.com");
var requestBody = new
{
text = "Test",
from = new { textFrom = "+15551212" },
to = new object[] { new { sendTo = "+15551231" } }
};
var response = await extension.Sms().Post(requestBody); //Can't get past this point.
}





5 Answers
answered on Jan 8, 2021 at 7:09am  

Neither do I, That is not where I am getting the info from, I am using this. And there is no provision for adding a direct number?? I tried this with Python and it it worked fine...has something changed?
1610118486539.png


 0
on Jan 8, 2021 at 7:34am   •  0 likes

After the code below, can you print the "resp" object as string and post it here.

var resp = await restClient.Restapi().Account().Extension().PhoneNumber().Get();

on Jan 8, 2021 at 7:51am   •  0 likes

No, It is throwing CompanyPhoneNumberInfo does not contain a definition for 'for 'records'
I tried changing it to this:

CompanyPhoneNumberInfo resp = await restClient.Restapi().Account().Extension().PhoneNumber().Get();


then in the foreach I tried this:


foreach (CompanyPhoneNumberInfo record in resp.records)
{
foreach (CompanyPhoneNumberInfo feature in record.features)
{


Same exception.



on Jan 8, 2021 at 8:19am   •  0 likes

I asked you to print the response, not parsing it w/o knowing what it returns.

var response = await rc.Restapi().Account().Extension().PhoneNumber().Get();
dynamic jsonStr = JsonConvert.SerializeObject(response);
Console.WriteLine(jsonStr);


on Jan 8, 2021 at 7:26am   •  0 likes

The site you visit is the RingCentral Developer portal. It is different than the sandbox account admin portal. To setup and config your sandbox such as adding new users, adding new numbers ect. you need to login https://service.devtest.ringcentral.com with your sandbox user's login credentials (not the login credentials for the dev portal!). Alternatively, you can click the "Sandbox Accounts" option from the view you showed above and click on the up-arrow which will log you in the sandbox admin portal.

I will investigate the C# later.

on Jan 8, 2021 at 7:36am   •  0 likes

Okay, I see it now, I will have to get the password from them, strange something has changed as I was able to use the information above to send SMS (with Python). As far as the C# goes the only error(s) I could find where in the foreach statements.

Thanks

answered on Jan 8, 2021 at 9:07am  

Nothing, It freezes. No exceptions nothing.


 0
on Jan 8, 2021 at 9:13am   •  1 likes

Once you could try Python code, can you use this Python code?

https://developers.ringcentral.com/guide/messaging/quick-start#python

on Jan 8, 2021 at 9:15am   •  0 likes

Thanks, I think I will try convincing them to use Python instead.

on Jan 8, 2021 at 9:18am   •  0 likes

Don't need to. I just want to see the differences between using the .Net SDK and the Python SDK in your particular case.

BTW, what is the RingCentral .Net SDK version are you using?

on Jan 8, 2021 at 10:49am   •  0 likes

v4.0.30319

on Jan 8, 2021 at 11:17am   •  0 likes

I am not aware of a version .30319. The current version is 4.1.0. Can you update the SDK

on Jan 8, 2021 at 11:21am   •  0 likes

Okay, it's now v4.0.30319

on Jan 8, 2021 at 11:01am   •  0 likes

Not much luck with python either I am getting

ringcentral.http.api_exception.ApiException: Unauthorized for this grant type

on Jan 8, 2021 at 11:20am   •  0 likes

you got to try with this app instead "SMSSendTest5". This app is password flow and should work with the sample code authentication.

on Jan 8, 2021 at 11:33am   •  0 likes

Im really not having much luck

In python

ringcentral.http.api_exception.ApiException: In order to call this API endpoint, application needs to have [ReadAccounts] permission


Tried changing it in the C# version as well but that foreach is still jamming me up.

on Jan 8, 2021 at 11:36am   •  0 likes

Then add the ReadAccounts permission to the app

on Jan 8, 2021 at 11:38am   •  0 likes

Also, it look like this app "ChiliSMS" has more serious problem. It has no permissions at all.

Please go thru our dev guide and documentation to learn basic steps.

on Jan 8, 2021 at 11:46am   •  0 likes

Okay,

Now it's working...I will delete ChiliSMS, not sure who put that there. Anything on that foreach statement:

foreach (var record in resp.records) I think it will work if I can get past that...

answered on Jan 8, 2021 at 8:50am  

Same result; CS1061 CompanyPhoneNumberInfo does not contain a definition for records


 0
on Jan 8, 2021 at 9:01am   •  0 likes

Comment out the foreach lines! Just print the response which will not have anything to do with the CompanyPhoneNumberInfo object.

answered on Jan 8, 2021 at 3:20am  

I am usinh 3136362490


 0
on Jan 8, 2021 at 6:56am   •  0 likes

I don't know why the phone-number endpoint return null from your account. It should at least return the main company number. But looking into your sandbox account, I see you don't have any other number added to the user "101".

screen-shot-2021-01-08-at-65207-am.png

You can login your sandbox service web, browse to the page as shown above, then click the Add Direct Number and follow the instructions to add a number to the user extension.

Test it again.

answered on Jan 7, 2021 at 9:03am  

Check out this quick start sample code to use the SDK for sending SMS messages.

https://developers.ringcentral.com/guide/messaging/quick-start#c#


 1
on Jan 7, 2021 at 10:26am   •  0 likes

Thanks, There seems to be a problem in

static private async Task read_extension_phone_number()

here
foreach (var record in resp.records) //This throws CS1061
//CompanyPhoneNumberInfo does not contain a definition for 'records'

there are also some other problems with the record variable

on Jan 7, 2021 at 11:58am   •  0 likes

Looks like your test account does not have any number. Can you check if the resp.records is null or an empty array?

on Jan 7, 2021 at 12:06pm   •  0 likes


Thanks, Can't tell it's telling me resp has nothing like records or features there is no definition for either one in the foreach. Anyway I looked at the account and there is a number for the account, is that it?

on Jan 7, 2021 at 1:34pm   •  0 likes

What is your sandbox account main company number?



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