Question

The remote server returned an error: (401) Unauthorized

  • 12 March 2020
  • 2 replies
  • 1901 views

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 replies

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

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.

Reply