Calendly API returns a 401

1.7k Views Asked by At

I want to do an API call using request of my user in Calendly like Documentation but I can't do it. I don't know if I need something else in my code, thanks.

import requests, json

api_key = 'aaaaaaaaa'
header = {
    'Authorization' : api_key
}

response = requests.get('https://api.calendly.com/users/me/', headers= header)
print(response)
print(response.json())

I'm getting a 401 response:

<Response [401]> {'title': 'Unauthenticated', 'message': 'The access token is invalid'}
2

There are 2 best solutions below

4
On BEST ANSWER

I suspect you're trying to use the API Key for API v2. The API Key only works with Calendly's legacy API v1. API v2 supports the following two authorization schemes:

  • OAuth authorization code flow, or
  • Personal Access Tokens.

See developer.calendly.com/getting-started for more details.

0
On

If you are using a personal token with the API v2, you need to prepend Bearer before your token.

Example:

header = {
    'Authorization': f'Bearer {api_key}'
}

Source: https://calendly.stoplight.io/docs/api-docs/YXBpOjM5NQ-calendly-api