question

Senthil Kumar avatar image
Senthil Kumar asked Phong Vu answered

The remote server returned an error: (401) Unauthorized

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..

rest api
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Anirban avatar image
Anirban answered Anirban edited

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

1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered

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 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys