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
The remote server returned an error: (401) Unauthorized
Tags: rest api
Mar 12, 2020 at 7:33am   •   2 replies  •  0 likes
Senthil Kumar

Using visual studio 2015, C#, constructed code to send sms using Ring Central SMS api,

Error details :- "The remote server returned an error: (401) Unauthorized."

Error while running the below code:

var JSONstr = new StringBuilder();

System.Net.WebRequest req = null;

System.Net.WebResponse rsp = null;

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;

JSONstr.Append("{");

JSONstr.Append("\"to\"" + ":" + " [{" + "\"phoneNumber\"" + ":" +"\"+1234567890\"" + "}]" + ",");

JSONstr.Append("\"from\"" + ":" + " [{" + "\"phoneNumber\"" + ":" + "\"+12587419632\"" + "}]" + ",");

JSONstr.Append("\"text\"" + ":" + "\"Test SMS message\"");

JSONstr.Append("}");


string uri = "https://platform.ringcentral.com/restapi/v1.0/account/+19294682441/extension/101/sms";

if (uri != string.Empty && uri != null)

{


req = System.Net.WebRequest.Create(uri);

req.Method = "POST";

req.ContentType = "application/json";


System.IO.StreamWriter writer = new System.IO.StreamWriter(req.GetRequestStream());

writer.WriteLine(JSONstr.ToString());

writer.Close();

rsp = req.GetResponse();


Kindly help me..

2 Answers
answered on Mar 12, 2020 at 8:27pm  

Any reason you don't use the RingCentral .Net SDK?

What you put in the uri is so wrong

string uri = "https://platform.ringcentral.com/restapi/v1.0/account/+19294682441/extension/101/sms";

It is the account id not the username (phone number), and the extension id not the extension number 101. Those ids are read from the platform.


 1
answered on Mar 12, 2020 at 10:07am  

How are you passing authorization token code?

First you need to check if your Client ID and Client secret for this new API is valid. Then check if you are passing the correct oauth token. And then make sure if you are hitting correct url for sms


 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