1. How to create a managed organizations
First, manually create an OAuth client in https://app.cal.com/settings/platform. Second, make a POST request tohttps://api.cal.com/v2/organizations/:organizationId/organizations to create a managed organization and receive its api key:
- Replace
:organizationIdin the URL with your organization Id that you can copy from OAuth client settings. - Add authentication headers
x-cal-client-idequal to OAuth client id andx-cal-secret-keyequal to the OAuth client secret. - Add request body
apiKey only now, so make sure to create a table in your database where you store managed organization’s id and apiKey . The apiKey will be used to create an OAuth client that is used to create platform users.
Using same x-cal-client-id and x-cal-secret-key headers you can make requests to:
- Fetch managed organization by making GET request to
https://api.cal.com/v2/organizations/:organizationId/organizations/:managedOrganizationId - Fetch all managed organizations by making GET request to
https://api.cal.com/v2/organizations/:organizationId/organizations - Update managed organization by making PATCH request to
https://api.cal.com/v2/organizations/:organizationId/organizations/:managedOrganizationIdwith body where you can specify either “name” or “metadata” - Delete managed organization by making DELETE request to
https://api.cal.com/v2/organizations/:organizationId/organizations/:managedOrganizationId
2. How to create OAuth client for a managed organization
Now that you have created a managed organization and have itsapiKey you can create OAuth clients for the managed organization.
Make POST request to https://api.cal.com/v2/oauth-clients by:
- Setting
Authorization: Bearer <apiKey>header where<apiKey>is api key returned when creating a managed organization. - Setting request body:
- name is name of the OAuth client
- permissions - an array that can receive following permissions:
"EVENT_TYPE_READ", "EVENT_TYPE_WRITE", "BOOKING_READ", "BOOKING_WRITE", "SCHEDULE_READ", "SCHEDULE_WRITE", "APPS_READ", "APPS_WRITE", "PROFILE_READ", "PROFILE_WRITE"or if you want all of them enabled set*. You most probably want to use*. See docs here https://cal.com/docs/platform/quickstart#2-setting-up-an-oauth-client - redirectUris - point to (as example)
your-domain.com*where users end up when connecting google calendar etc and what is the origin of the requests aka what origins are allowed to make requests to our endpoints. Havingyour-domain.com*would mean that we will accept requests from cal UI components that make requests fromyour-domain.com, your-domain.com/pageetc.
https://api.cal.com/v2/oauth-clients by:
- Setting
Authorization: Bearer <apiKey>header where<apiKey>is the api key returned when creating a managed organization.
https://api.cal.com/v2/oauth-clients/:oAuthClientId by:
- Setting
Authorization: Bearer <apiKey>header where<apiKey>is the api key returned when creating a managed organization.
3. How to refresh api key of a managed organization
If you did not specifyapiKeyNeverExpires when creating a managed organization then you will have to refresh the api key after apiKeyDaysValid (if you specified it) or by default after 30 days.
Make a POST request to https://api.cal.com/v2/api-keys/refresh by:
- Setting
Authorization: Bearer <apiKey>header where<apiKey>is api key returned when creating a managed organization. - Add a request body
{"apiKeyDaysValid": 30}or whatever number of days you want the new api key to be valid or{"apiKeyNeverExpires": true}if you want that it never expires.