Skip to main content
Solved

Unauthorized Grant Type - Pull Call Log API w/ Python

  • December 5, 2022
  • 2 replies
  • 349 views

I'm attempting to pull data from a Sandbox Env - Call Log. There is confirmed one record on the Call Log, for context. I'm using a Sandbox App that uses JWT Auth. When I run 'python3 pray.py' in Terminal, I get the following error:

Unable to authenticate to platform. Check credentials.Unauthorized for this grant type

Here is the code I'm running:

from ringcentral import SDK
 
RINGCENTRAL_CLIENTID = 'hTTB9Rt9QT6ctmCyK9c2EA'
RINGCENTRAL_CLIENTSECRET = 'sP8##############################PG4Qg'
RINGCENTRAL_SERVER = 'https://platform.devtest.ringcentral.com'
 
rcsdk = SDK( RINGCENTRAL_CLIENTID, RINGCENTRAL_CLIENTSECRET, RINGCENTRAL_SERVER)
platform = rcsdk.platform()
 
JWT_TOKEN = "eyJraWQiOiI########################################MjU2In0"
 
try:
    platform.login( jwt=JWT_TOKEN )
    params = {
        'dateFrom': "2012-01-01T00:00:00.000Z"
        }
    resp = platform.get('/restapi/v1.0/account/~/extension/~/call-log', params)
    for record in resp.json().records:
        print ("Call type: " + record.type)
except Exception as e:
    print ("Unable to authenticate to platform. Check credentials." + str(e))

I have given the Sandbox App every single permission available, including Read Call Log. My Python3 version is Python 3.8.9.

What could be causing this issue? I appreciate any help that can be provided. I scoured other similar questions on the forum, but I was unable to fix with those resolutions.

Best answer by PhongVu

Nothing is wrong with the code. And the error is about authentication so app permission is not an issue here.

I check your app and look at the JWT token from your dev portal and I am not sure if you copy the right one. I see the valid one you cerated today in the dev portal is ending with different chars as what you shorten and showed above. This is what I see from your dev portal. Can you double check it.

JWT = "eyJraWQ######################################zelzQ"

2 replies

PhongVu
Community Manager
Forum|alt.badge.img
  • Community Manager
  • Answer
  • December 5, 2022

Nothing is wrong with the code. And the error is about authentication so app permission is not an issue here.

I check your app and look at the JWT token from your dev portal and I am not sure if you copy the right one. I see the valid one you cerated today in the dev portal is ending with different chars as what you shorten and showed above. This is what I see from your dev portal. Can you double check it.

JWT = "eyJraWQ######################################zelzQ"

  • Author
  • New Participant
  • December 5, 2022

Ah! I thought it was the JWT from the App itself. Didn't realize I was using the User JWT. This worked. Thank you!