question

Shelby Tolliver avatar image
Shelby Tolliver asked Shelby Tolliver answered

400 BadRequest - C# Client - RestClient call to Authorize

Following code :

var rc = new RestClient(appConfig.RingCentralClientId, appConfig.RingCentralClientSecret, appConfig.RingCentralApiServerUrl);
TokenInfo tokenInfo = await rc.Authorize(code, productDomain + ringCentralOauthTokenCallbackUrl); // "code" comes from RingCentral response to initial call to "AuthorizeUri".


Results in the following error:

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.


Exception Details: Flurl.Http.FlurlHttpException: Call failed with status code 400 (Bad Request): POST https://platform.devtest.ringcentral.com/restapi/oauth/token


Stack Trace:

[FlurlHttpException: Call failed with status code 400 (Bad Request): POST https://platform.devtest.ringcentral.com/restapi/oauth/token]   Flurl.Http.<HandleExceptionAsync>d__23.MoveNext() +565   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +48   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +230   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +143   System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +50   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +40   Flurl.Http.<SendAsync>d__19.MoveNext() +2946   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +48   Flurl.Http.<SendAsync>d__19.MoveNext() +3738   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +48   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +230   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +143   System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +50   System.Runtime.CompilerServices.ConfiguredTaskAwaiter.GetResult() +40   Flurl.Http.<ReceiveJson>d__0`1.MoveNext() +392   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +48   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +230   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +143   System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +50   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +40   RingCentral.<Authorize>d__44.MoveNext() +487   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +48   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +230   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +143   System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +50   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +40   AsclepiusWeb.Core.Service.CallRecords.CallerIqPlugins.<getAccessTokens>d__7.MoveNext() in C:\dev\asclepius\source\AsclepiusWeb\Core\Service\CallRecords\CallerIqPlugins\CallerIqPluginService.cs:52   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +48   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +230   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +143   System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +50   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +40   AsclepiusWeb.Areas.clients.Controllers.<ringCentral>d__2.MoveNext() in C:\dev\asclepius\source\AsclepiusWeb\Areas\clients\Controllers\CallerIqOAuthController.cs:27   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +48   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +230   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +143   System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +50   System.Runtime.CompilerServices.TaskAwaiter.GetResult() +30   System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task) +63   System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +114   System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +66   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +47   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +137   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +49   System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +117   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +323   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +323   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +323   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +323   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +323   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +323   System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +44   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +47   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +137   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +50   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +72   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +134   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +134   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44   System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +134   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +134   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38   System.Web.CallHandlerExecutionStep.InvokeEndHandler(IAsyncResult ar) +279   System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +153



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

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

Shelby Tolliver avatar image
Shelby Tolliver answered

All 3 of those references are passing in username/password where I'm passing in the return code sent to me (via redirect uri) once the user accepts the use of the apps requested permissions. Don't know if that makes any difference. The one note that I thought may help was about disabling auto-refresh. I added the following command "rc.AutoRefreshToken = false" prior to making the call to authorize. Still seeing the same error.

1 |3000

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

Shelby Tolliver avatar image
Shelby Tolliver answered

Ok. Is there anything else I can provide here to help resolve this issue? I'm not getting any worthwhile detailed info on this error. Here's what the error says...

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Flurl.Http.FlurlHttpException: Call failed with status code 400 (Bad Request): POST https://platform.devtest.ringcentral.com/restapi/oauth/token


Again, I'm using the C# RestClient to call "Authorize" and I'm passing in the code returned to me by RingCentral along with a redirect-url.


Here's a more palatable stack trace. Sorry for the mess in the original post...

[FlurlHttpException: Call failed with status code 400 (Bad Request): POST https://platform.devtest.ringcentral.com/restapi/oauth/token]
   Flurl.Http.<HandleExceptionAsync>d__23.MoveNext() +565
   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +48
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +230
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +143
   System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +50
   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +40
   Flurl.Http.<SendAsync>d__19.MoveNext() +2945
   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +48
   Flurl.Http.<SendAsync>d__19.MoveNext() +3737
   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +48
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +230
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +143
   System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +50
   System.Runtime.CompilerServices.ConfiguredTaskAwaiter.GetResult() +40
   Flurl.Http.<ReceiveJson>d__0`1.MoveNext() +392
   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +48
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +230
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +143
   System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +50
   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +40
   RingCentral.<Authorize>d__44.MoveNext() +487
   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +48
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +230
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +143
   System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +50
   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +40
   AsclepiusWeb.Core.Service.CallRecords.CallerIqPlugins.<getAccessTokens>d__9.MoveNext() in C:\dev\asclepius\source\AsclepiusWeb\Core\Service\CallRecords\CallerIqPlugins\RingCentralApiClient.cs:47
   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +48
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +230
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +143
   System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +50
   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +40
   AsclepiusWeb.Areas.clients.Controllers.<ringCentral>d__2.MoveNext() in C:\dev\asclepius\source\AsclepiusWeb\Areas\clients\Controllers\CallerIqOAuthController.cs:27
   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +48
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +230
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +143
   System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +50
   System.Runtime.CompilerServices.TaskAwaiter.GetResult() +30
   System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task) +63
   System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +114
   System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +66
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +47
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +137
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +49
   System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +117
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +323
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +323
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +323
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +323
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +323
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +323
   System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +44
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +47
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +137
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +50
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +72
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +134
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +134
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
   System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +134
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +134
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
   System.Web.CallHandlerExecutionStep.InvokeEndHandler(IAsyncResult ar) +279
   System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +153 


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

Follow this quick start sample https://developers.ringcentral.com/guide/authentication/quick-start.

You don't call the .authorize() that way. Where did you get that idea or instruction?

TokenInfo tokenInfo = await rc.Authorize(code, productDomain + ringCentralOauthTokenCallbackUrl);


1 |3000

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

Shelby Tolliver avatar image
Shelby Tolliver answered

Whether I call Authorize with or without the TokenInfo assignment (as in the quick-start guide that you point to) I still get the same, useless, error. Very frustrating. I'm not using dotnet core either (as the guide does)

1 |3000

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

Shelby Tolliver avatar image
Shelby Tolliver answered

Ok. Just to follow up. Turns out the reason for the "Bad Request" is because the url I specified in the call to "Authorize" was not the same as the one specified in the call to "AuthorizeUrl". Am a little surprised because both url's are registered in my sandbox application. In any event, I'm now beyond that hurdle. Thanks for all the various hints.

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