question

yanmei avatar image
yanmei asked Anirban edited

can't get Access Token

I am using VB Code, Here is code:

request = DirectCast(WebRequest.Create("https://platform.devtest.ringcentral.com/restapi/oauth/token HTTP/1.1"), HttpWebRequest)

Dim Credidentials As String = "NF3Unhp_R4yBV2QoMNM0yw" & ":" & "3ONXJwFDS2akvz2CaPZX9AaGAzR8uPTUS1h4z80lGtcA"

Credidentials = Convert.ToBase64String(Encoding.Default.GetBytes(Credidentials))


' Add authentication to request

Dim Userdata As String = "grant_type=password&username=12143477228&extension=101&password=POR2008$"

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

request.Method = "POST"

request.Host = "platform.devtest.ringcentral.com"

request.Headers("Authorization") = "Basic " & Credidentials & "&" & Userdata

request.Accept = "application/json"

ServicePointManager.ServerCertificateValidationCallback = AddressOf AcceptAllCertifications


return error : the remote server returned an error: (404) Not Found


I just want to get access token, then I can continue to do next api call.

getting started
1 |3000

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

John Wang avatar image
John Wang Deactivated answered
This has been made private because app and user credentials have been included in the post. Please do not post your app secret or user passwords openly.

I'm not sure why you are receiving a 404 (is it confirmed to be sending to https?).

User data is supposed to be in the body, not in the Authorization header.

1 |3000

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

yanmei avatar image
yanmei answered benjamin-dean commented

thanks. I move UserData to body, get different error:  (401) Unauthorized.

I am using sandbox environment. and sand box account


3 comments
1 |3000

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

John Wang avatar image John Wang ♦♦ commented ·
The data must be URI encoded so your $ should be encoded to %24. Try it with the $ converted to %24.

You can use an online encoder/decoder to test:  http://meyerweb.com/eric/tools/dencoder/
0 Likes 0 ·
yanmei avatar image yanmei commented ·

hi, I do encoded body as

UserData = "grant_type=password&username=xxxxxxxx&password=xxxxxxxx&extension=xxx"

Dim body As Byte() = System.Text.Encoding.UTF8.GetBytes(UserData)

still no luck. Unauthorized error (401)

0 Likes 0 ·
benjamin-dean avatar image benjamin-dean commented ·
Have you tried using the API Console to test obtaining an access_token:  https://developers.ringcentral.com/api-explorer/latest/index.html#/!/Authentication/post_oauth_token

Start there using your credentials. If that works, then make sure to follow the documentation and information provided in the API reference for authorization:  https://developers.ringcentral.com/api-docs/latest/index.html#!#RefGetToken.html
0 Likes 0 ·
yanmei avatar image
yanmei answered
I did test in API console, and got Access_token, I used same Credidentials in HttpWebRequest, just did not work. (401) Unauthorized. it's weird.
1 |3000

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

yanmei avatar image
yanmei answered
I got it work, I remove HTTP 1.1 in URL, In RingCentral Document, there is http 1.1 required, that's wrong. anyway, Thanks for help.
1 |3000

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

benjamin-dean avatar image
benjamin-dean answered
Could you provide the final HTTP POST request you used (minus your API keys) so we can compare and update our documentation (in case this fouls up any other developers)?

Thanks,
Benjamin
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

Yes, need to take care the url part https://platform.devtest.ringcentral.com/restapi/oauth/token as documents are sometimes misleading.. like the case here where you were appending HTTP/1.1 in url which is wrong.

Things need to be noticed by developers while copying examples from documents

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