Question

C# Authorization 400 - Bad Request

  • 24 January 2018
  • 5 replies
  • 1952 views

  • New Participant
  • 3 replies

I'm using the latest official C# SDK in a new ASP.NET Core 2.0 web application. Although the SDK isn't built to the same target framework, the app compiles and seems ok. I've tried just about every setting (public/private, web, web/ui, etc.) but I always get the following error:


FlurlHttpException: Request to https://platform.devtest.ringcentral.com/restapi/oauth/token failed with status code 400 (Bad Request).


I'm using simple code which appears the same as the SDK sample:


var restClient = new RestClient(appKey, appSecret, appUri);

await restClient.Authorize(userName, extension, password);


If you're able to look up my account info to verify, the sandbox values I'm using are:

  1. appKey = f6v********-61******kw
  2. appSecret = JR****u_QG**************TxA
  3. appURI = https://platform.devetest.ringcentral.com
  4. userName = +1313*****01
  5. extension = 101
  6. password = 1rc********st!

All the above are from the sandbox app credentials. I wish I received something more back, but I just get "400 (Bad Request)". I'm sure it's something dumb I'm doing, it is rather confusing figuring out what values are needed when they are called different things in different places.


Any help is greatly appreciated, I've scoured the community forum and the web. It seems that this error is generally from people not using the sandbox credentials, or the wrong password, but I've changed the sandbox password a zillion times, to no avail.


Thank you!


5 replies

And of course, about 2 minutes after I post this it starts working, lol.  Go figure.

Sorry to be a pest.


Userlevel 1
Isn't it because of the wrong appURI https://platform.devetest.ringcentral.com? The correct one is https://platform.devtest.ringcentral.com 

+ Phong
No, I just fat fingered that here, it was set properly in my code.  Either way, it's working now, every time, so I'm not going to fret :)
How is it work now.Can you please explain
My code is pretty simple:

var restClient = new RestClient(appKey, appSecret, appUri);
await restClient.Authorize(userName, extension, password);            
var requestBody = new
      {
             text,
             from = new { phoneNumber = from },
             to = new object[] { new { phoneNumber = to } }           
      };
var rcExtension = restClient.Restapi().Account().Extension();
var response = await rcExtension.Sms().Post(requestBody);
if (response.messageStatus == "Queued" && response.deliveryErrorCode == null)
{
      return true;            
 }
 else
 {
       return false;
 }

The arguments/vars of 'appKey', 'appSecret', 'appUri', 'userName', 'extension' and 'password' are passed in from my appsettings.json and 'from', 'to', and 'text' are passed in from the caller.  All would obviously need set by you.

Reply