Search.../

connectByOAuth( )

Developer Preview

Connects to an external calendar using the OAuth authorization protocol.

Description

The authorization flow should take place as follows:

  1. Call the function with the appropriate parameters.
  2. Redirect the user to the URL received in the response.
  3. The user authorizes access.
  4. The user is redirected to the URL you provide in the redirectUrl parameter, with a query parameter connectionId containing the new connection ID.

If the attempt to connect fails, the user is still redirected to the URL you provide in the redirectUrl parameter, but with a query parameter error containing one of the following values:

  • reject: The user rejected the authorization request.
  • unsupported: Connecting to the user's external account type is not supported by the provider.
  • internal: An error unrelated to the client or the request that prevents the server from fulfilling the request.

Once a connection is successfully created, use listEvents() to obtain an up-to-date list of events in the connected external calendars.

Note: Use listProviders() to find out whether to connect to a particular provider using this endpoint or connectByCredentials().

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function connectByOAuth(providerId: string, scheduleId: string, redirectUrl: string): Promise<ConnectByOAuthResponse>

connectByOAuth Parameters

NAME
TYPE
DESCRIPTION
providerId
string

ID of the external calendar provider. Find this with the listProviders() function.

scheduleId
string

ID of the schedule to connect with the external calendar account.

redirectUrl
string

URL to redirect the user to after they authorize access to the external calendar account.

If the connection is successfully established, the user is redirected to this URL with a query parameter connectionId containing the new connection ID. If the attempt to connect fails, the user is redirected to this URL with a query parameter error containing the error type.

Returns

Return Type:

Promise<
ConnectByOAuthResponse
>
NAME
TYPE
DESCRIPTION
oauthUrl
string

URL of the external calendar authorization page to redirect the user to.

Was this helpful?

Connect with an external calendar by OAuth

Copy Code
1import {externalCalendars} from 'wix-bookings.v2';
2
3async function connectByOAuth(providerId, scheduleId, redirectUrl) {
4 const {oauthUrl} =
5 await externalCalendars.connectByOAuth(providerId, scheduleId, redirectUrl)
6 return oauthUrl
7}