API call to Authorize from Postman

  • 1
  • Question
  • Updated 4 weeks ago
Hi all, I am trying to test the API call to Authorize RingCentral from Postman and I am receiving 'Could not complete oauth login' error. Attached the screen shot of my request. 




Access Token URL: https://platform.devtest.ringcentral.com/restapi/oauth/token

Thanks!
Photo of Sara

Sara

  • 182 Points 100 badge 2x thumb

Posted 4 weeks ago

  • 1
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,802 Points 5k badge 2x thumb
Try to specify "Token Name"  as "access_token"
Photo of Sara

Sara

  • 182 Points 100 badge 2x thumb


Still same error.
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,802 Points 5k badge 2x thumb
I don't use postman very often and I don't even know how to bring up the UI as shown in your screenshot.

Could you please tell me how to reproduce the issue quickly?  Especially how can I bring up the "GET NEW ACCESS TOKEN" dialog?
Photo of Sara

Sara

  • 182 Points 100 badge 2x thumb


select OAuth 2.0 from the dropdown and it will display 'NEW ACCESS TOKEN'
Photo of Sara

Sara

  • 182 Points 100 badge 2x thumb
*and it will display 'GET NEW ACCESS TOKEN' button.
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,802 Points 5k badge 2x thumb


Above works like a charm for me.
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,802 Points 5k badge 2x thumb
When you click the "Request Token" button, there will be a modal window. Isn't it the same for you?

By the way, I am using PostMan Version 6.3.0 (6.3.0)  for macOS
Photo of Sara

Sara

  • 182 Points 100 badge 2x thumb
I updated Postman and I am using same version. Now i am receiving the following error
{
  "error" : "invalid_grant",
  "error_description" : "Redirect URIs do not match",
  "errors" : [ {
    "errorCode" : "OAU-109",
    "message" : "Redirect URIs do not match"
  } ] 
}

I gave redirect uri as https://www.getpostman.com/oauth2/callback

Can you tell me what would be the redirect URI? I never worked on OAuth2 API call and I am really confused. 
 
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,462 Points 5k badge 2x thumb
You need to login developer.ringcentral.com and edit your app to set your redirect uri.

The uri used in postman should match the one you set in your RingCentral app.
Photo of Sara

Sara

  • 182 Points 100 badge 2x thumb
yes, I was making sure the RC uri and request uri are same. But I was getting 'URI does not match error'. 

Everything is working fine now. 
Actually I am trying to make a REST api call from Salesforce to send sms via Ringcentral. I just wanted to test the Authorization part using postman before jumping into Apex. I am able to get the token using Apex.
Photo of Sara

Sara

  • 182 Points 100 badge 2x thumb
It is working. I tried with another app in RingCentral and it is working now. Thanks for your help.
Photo of Sara

Sara

  • 182 Points 100 badge 2x thumb
Hey Tyler, is it possible to make the authorize call automatically? or we need to login manually to authorize the request? 
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,138 Points 5k badge 2x thumb
I am afraid that you have to do it manually because you need to enter password to authorize.

But if you do the password flow, it could be automatic
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,138 Points 5k badge 2x thumb
Check this: https://medium.com/ringcentral-developers/use-curl-to-access-ringcentral-platform-api-d4710fe68fa4

It's about curl which solves similar problems as postman.
Photo of Sara

Sara

  • 182 Points 100 badge 2x thumb
Another scenario

I am trying the following method of call using Apex 

  1. Made an Authorize call to RC https://platform.devtest.ringcentral.com/restapi/oauth/authorize, Authorize call was successful and returned the 'code: XXXXXXXX' with response 
  2. Used the Code: XXXXXXX with params to make a token call https://platform.devtest.ringcentral.com/restapi/oauth/token but getting 400 error. 
Complete URL:

'https://platform.devtest.ringcentral.com/restapi/oauth/authorize?response_type=code&client_id=<CLIENT ID>&client_secret=<SECRET> &redirect_uri=<REDIRECT URI>&state=step2'

'https://platform.devtest.ringcentral.com/restapi/oauth/token?code=<AUTHIRIZE CODE FROM THE RESPONSE>&grant_type=password&client_id=<CLIENT ID>&client_secret=<SECRET> &redirect_uri=<REDIRECT URI>'


Any thoughts?
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,138 Points 5k badge 2x thumb
Check the response body of the 400 error.

grant_type should be "authorization_code" instead of "password". 

Ref: https://github.com/ringcentral/ringcentral-ruby/blob/master/lib/ringcentral.rb#L50-L54
Photo of Sara

Sara

  • 182 Points 100 badge 2x thumb
I am receiving 'Account does not exist' error.
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,802 Points 5k badge 2x thumb
If you want to jump to Apex sooner or later. Why not simply try some programming language instead of Postman?

As far as I can tell, Apex is similar to Java.  Here is how we do the authorization in Java: https://github.com/ringcentral/ringcentral-java/blob/master/src/main/java/com/ringcentral/RestClient...
Photo of Sara

Sara

  • 182 Points 100 badge 2x thumb
Postman is successful. The 400 error I am receiving is through APEX call. Below is the response from Authorize Request.

22:28:07:007 USER_DEBUG [26]|DEBUG|Authorize Response: {code=XXXXXXXXX, state=step2}

I am trying to pass the code with the following token Request and receiving 'Accont does not exist' as response body.

'https://platform.devtest.ringcentral.com/restapi/oauth/token?code=<CODE>&grant_type=password&client_id=<CLIENT ID>&client_secret=<SECRET> &redirect_uri=<REDIRECT URI>'

Photo of Tyler Long

Tyler Long, Official Rep

  • 7,802 Points 5k badge 2x thumb
client_id and client_secret should be used in HTTP Header for basic authorization.  They are not supposed to be in query string.

And you are doing authorization code flow. So query parameter  "grant_type=password" should be changed to "grant_type= authorization_code"
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,802 Points 5k badge 2x thumb
Postman is successful while Apex code is not. Because what the Apex code does it not what Postman does.
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,802 Points 5k badge 2x thumb
I highly recommend you to read https://github.com/ringcentral/ringcentral-ruby/blob/master/lib/ringcentral.rb  

170 line of code and covers all the things you need to know. Way more direct than trying everything with Postman.

For example: for authorization part: https://github.com/ringcentral/ringcentral-ruby/blob/master/lib/ringcentral.rb#L154-L165 
Before you get the token, use back authorization, otherwise use bearer authorization.

And in order to exchange code for token: https://github.com/ringcentral/ringcentral-ruby/blob/master/lib/ringcentral.rb#L49-L54
You can see that grant_type: 'authorization_code' and client_id & client_secret are not included in post body.(they are used in Basic authorization header instead)
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,802 Points 5k badge 2x thumb
And you don't have to use Apex because we don't have official SDK for Apex.

You can use Javascript instead because there are ways for Apex to communicate with JavaScript.  Check this video from me: https://www.youtube.com/watch?v=bf_Z391G2cw&t=1182s

RingCentral has official SDK for JS https://github.com/ringcentral/ringcentral-js

Here is a community version maintained by me: https://github.com/tylerlong/ringcentral-js-concise
(Edited)
Photo of Sara

Sara

  • 182 Points 100 badge 2x thumb
Will check it out. Thanks for the info.