question

Senthil Kumar avatar image
Senthil Kumar asked ·

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

401
1 |1000 characters needed characters left characters exceeded

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

Anirban Sen Chowdhary avatar image
Anirban Sen Chowdhary answered ·

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

Share
1 |1000 characters needed characters left characters exceeded

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.

Share
1 |1000 characters needed characters left characters exceeded

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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