News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
400 Bad Request - Access denied [C#, HttpWebRequest]
Tags: getting started
May 16, 2016 at 9:08am   •   12 replies  •  0 likes
alex-.

Hello,

We are not using SDK. We are writing our library we need to get Access Toke. So we use C# then Httpwebrequest.


After passing all instructions on API DOCs we receiving

400 Bad Request - Access denied [C#, HttpWebRequest]


Could you help us.

Thank you

12 Answers
answered on Jun 8, 2016 at 10:54am  
That error usually means that the User credentials you are using do not belong to the same application/account (which is required during the initial stages of development).

Check that the username, extension, and password, are all part of a User/Extension which is enabled and defined in your Sandbox account in the [Sandbox version] of the Online Account Portal: https://service.devtest.ringcentral.com

 0
answered on Jun 6, 2016 at 9:22am  
Thanks Benjamin for your help, now I receive a different response with different error code (400):
{
"error": "invalid_client"
"error_description": "Access Denied."
}

the credentials are the ones provided by my Dashboard after the login..





 0
answered on Jun 6, 2016 at 8:33am  
Yes, many people have.

You might want to try changing your endpoint to: https://platform.devtest.ringcentral.com/restapi/oauth/token (that is the route to get an access_token per the API docs).

Let me know if that works.

 0
answered on Jun 2, 2016 at 3:10am  
Thanks a lot Benjamin! I changed it and I had a problem with the new version of the Rest client used in the guidelines (certificate)
https://restforchrome.blogspot.co.uk/2016/04/advanced-rest-client.html
https://bugs.chromium.org/p/chromium/issues/detail?id=603104

Then I switched to postman (alternative extension/app to play with Rest) and despite of I am using credentials from my sandbox dashboard (number with +44 prefix and extension..) I am getting status 404:



any idea? Did someone succeed in following the getting started guidelines?

thanks in advance!
Fabio

 0
answered on Jun 1, 2016 at 9:19am  
It looks like you're using the Production API Base URL instead of the Sandbox. If you have not applied for Production Access for your app/integration, you MUST use the Sandbox API Base URL. I have them both listed below:

Production API Base URL: https://platform.ringcentral.com
Sandbox API Base URL: https://platform.devtest.ringcentral.com

If that does not work and you still receive the "invalid_client" message, keep using the Sandbox API Base URL, but verify that the User credentials you're passing are actually a User defined in the Sandbox account (https://service.devtest.ringcentral.com).

 0
answered on Jun 1, 2016 at 7:02am  
Hi,
I correctly followed the Getting Started guide from here:
https://developer.ringcentral.com/library/tutorials/get-started.html

using valid username and password (I logged in with them into the dashboard section from where I copied the authentication keys and encoded to base64).

but I get an access denied so I cannot obtain the Access Token (point B from the Getting started guide):





any idea?

 0
answered on May 16, 2016 at 3:41pm  
Authorization Code === 3-Legged OAuth2 in RingCentral. This would be grant_type=authorization_code

You want Password Flow if you are using grant_type=password.

You can take a look at Grokify's RingCentral OAuth Demos here, it might help if you need to implement 3-Legged OAuth: https://github.com/grokify/ringcentral-demos-oauth

Keep in mind, you cannot modify the Platform Type for an application once it is created. You must create a new application in the Developer Portal (but that means in your code you're really only changing your API keys and auth flow...everything else should be the same).

 0
answered on May 16, 2016 at 3:10pm  
I would try it on the API explorer.  

Also check the OAuth settings of your app on the Developer network.  

Your application may not qualify for this type of authentication.

For the password flow authentication you need:

Authorization
Flows 

Authorization Code; Password flow; Refresh Access Token

 

 0
answered on May 16, 2016 at 3:00pm  
You will receive that error message if your application type does not match the RingCentral OAuth2 flow you're attempting to use.

If you are trying to use "grant_type=password", your Application's Platform Type in the Developer Portal must be set to "Server Only".

You can read more about this here: https://developers.ringcentral.com/library/tutorials/app-development.html#/#PlatformTypes

 0
answered on May 16, 2016 at 2:04pm  
Is anybody can help us with this error msg.


http://prntscr.com/b4vao7
http://prntscr.com/b4vag4

 0
answered on May 16, 2016 at 10:48am  
For the authorization method, I had to write the request parameters to the body as below and don't forget to change the content type.  The authorization header is set using the encoded value  explained by PathoGenius

Stream sRequest = null;           
StreamReader srResponse = null;
String sBody = String.Empty;
                    
sBody = "grant_type=password&username=" + appAccount + "&password=" + _t.password + "&extension=" + _t.extension;
byteBody = encoding.GetBytes(sBody);
HttpWReq.ContentLength = byteBody.Length;
//Add parameters to the Body - Go figure
sRequest = HttpWReq.GetRequestStream();
sRequest.Write(byteBody, 0, byteBody.Length);

HttpWReq.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";

HttpWReq.UserAgent = appName + "/" + appVersion;
                    HttpWReq.Headers[HttpRequestHeader.Authorization] = string.Format("{0} {1}", "Basic", authcode.Trim());



 0
answered on May 16, 2016 at 10:02am  

Something not specified in the API docs but constructed for you when using the API test and present in the example is the Authorization header value. You have to construct this using your App Key and App Secret. Concatenate them with a colon and encode it to Base64 for the request.

For testing, I used Python 2.7 to get the value.

import base64
appKey = 'asdfghjkl'
appSecret = 'qwertyuiop'
basic = base64.b64encode( appKey+':'+appSecret )
basic
>> 'YXNkZmdoamtsOnF3ZXJ0eXVpb3A='

Use the value in basic in the Authorization header

Authorization: Basic YXNkZmdoamtsOnF3ZXJ0eXVpb3A=
I used the Advanced REST Client Application in Chrome for my testing, but you should be able to duplicate the request using HttpWebRequest

 0



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us