I am currently trying to integrate with the latest OAuth API but run into a problem when trying to obtain the token. I was able to make a successful authorization request to receive the code needed. But when I try making the call to https://auth.calendly.com/oauth/token, I receive the following error:
bad request: :json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: '<'
I am following the API specs @ https://developer.calendly.com/api-docs/be9b32ef4b44c-get-access-token. I further can confirm that my credentials are valid because when I supply invalid data, e.g., wrong client_id, I am getting the expected error message for wrong credentials. Below is my code that I am currently using for the call in Python.
What am I doing wrong?
Thank you in advance,
-Andreas
def callback(self, request, *args, **kwargs):
# Extract the authorization code from the callback URL
authorization_code = request.GET.get('code')
# Exchange the authorization code for an access token
token_url = os.getenv('CALENDLY_ACCESS_TOKEN_URL')
client_id_and_secret = os.getenv('CALENDLY_CLIENT_ID') + ":" + os.getenv('CALENDLY_REDIRECT_URL')
token_params = {
"grant_type": "authorization_code",
"code": authorization_code,
"redirect_uri": os.getenv('CALENDLY_REDIRECT_URL'),
"client_id": os.getenv('CALENDLY_CLIENT_ID')
}
try:
headers = {
"Authorization": f'Basic {ViewSetUtil.encodeBase64(client_id_and_secret)}',
"Content-Type": "application/x-www-form-urlencoded"
}
response = requests.post(token_url, data=token_params, headers=headers)
return HttpResponse(response.text)
except Exception as e:
log.exception(f'pCalendly] Failed to authorize user {request.user.username}/{request.user.email}')
return HttpResponse('Authorization failed!')