> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# ConnectByCredentials

# Package: calendar

# Namespace: ExternalCalendarService

# Method link: https://dev.wix.com/docs/api-reference/business-solutions/bookings/calendar/external-calendar-v2/connect-by-credentials.md

## Permission Scopes:
Manage External Calendars: SCOPE.DC-BOOKINGS.MANAGE-EXTERNAL-CALENDARS
Manage External Calendars: SCOPE.DC-BOOKINGS.MANAGE-EXTERNAL-CALENDARS

## Introduction

Connects a [Wix schedule](https://dev.wix.com/docs/api-reference/business-management/calendar/schedules-v3/introduction.md)
to an external calendar account using credentials.

---

## REST API

### Schema

```
 Method: connectByCredentials
 Description: Connects a [Wix schedule](https://dev.wix.com/docs/api-reference/business-management/calendar/schedules-v3/introduction.md) to an external calendar account using credentials.   ### Next steps  After connecting an external calendar account to a Wix schedule, you can do the following.  #### Check the 2-way-sync settings  Call [List Connections](https://dev.wix.com/docs/api-reference/business-solutions/bookings/calendar/external-calendar-v2/list-connections.md) and filter by the relevant schedule GUID.  If needed, call [Update Sync Config](https://dev.wix.com/docs/api-reference/business-solutions/bookings/calendar/external-calendar-v2/update-sync-config.md) to adjust the syncing configuration.  #### Retrieve external calendar events  Once a connection is successfully created, you can call [List Events](https://dev.wix.com/docs/api-reference/business-solutions/bookings/calendar/external-calendar-v2/list-events.md) to obtain an up-to-date list of events in the connected external calendars.  ### When to call Connect By OAuth instead  You could call [Connect By OAuth](https://dev.wix.com/docs/api-reference/business-solutions/bookings/calendar/external-calendar-v2/connect-by-o-auth.md) if:  + The external calendar provider doesn't support authorization by credentials. + You don't have access to the external calendar account credentials. + You want the account owner to approve the connection.  Call [List Providers](https://dev.wix.com/docs/api-reference/business-solutions/bookings/calendar/external-calendar-v2/list-providers.md) for a complete list of external calendar providers supported on the Wix site, including which authorization methods they support.
 URL: https://www.wixapis.com/bookings/v2/external-calendars/connections:connectByCredentials
 Method: POST
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  providerId, scheduleId, email, password
 Method parameters: 
   param name: email | type: email | description: Email address for the external calendar account. | required: true | validation: format EMAIL
   param name: password | type: password | description: Password for the external calendar account. | required: true 
   param name: providerId | type: providerId | description: GUID of the external calendar provider. Find this with the [List Providers](#list-providers) endpoint. | required: true | validation: format GUID
   param name: scheduleId | type: scheduleId | description: GUID of the schedule to connect with the external calendar account. | required: true | validation: format GUID
 Return type: ConnectByCredentialsResponse
  - name: connection | type: Connection | description: Established connection details.  
     - name: id | type: string | description: GUID of the connection between the external calendar and the Wix site.  
     - name: providerId | type: string | description: GUID of the external calendar provider.  | validation: format GUID
     - name: calendarType | type: CalendarType | description: External calendar type.  
         - enum:
         -     UNDEFINED: There is no information about the external calendar type.
         -     GOOGLE: [Google Calendar](https://developers.google.com/calendar/api/guides/overview).
         -     I_CAL: Apple iCalendar.
         -     OUTLOOK: __Deprecated__. Use `MICROSOFT` instead.
         -     OFFICE_365: __Deprecated__. Use `MICROSOFT` instead.
         -     MICROSOFT: Microsoft Calendar. For example, Office 365 calendar or Outlook calendar.
         -     OTHER: A different type of external calendar, not listed here.
     - name: scheduleId | type: string | description: GUID of the [schedule](https://dev.wix.com/docs/rest/business-management/calendar/schedules-v3/introduction.md) that's connected to the external calendar.  | validation: format GUID
     - name: userId | type: string | description: GUID of the [Wix user](https://dev.wix.com/docs/rest/articles/getting-started/about-identities.md#wix-user) to whom the external calendar connection belongs.  | validation: format GUID
     - name: appId | type: string | description: GUID of the app which created the external calendar connection.  | validation: format GUID
     - name: externalAccountEmail | type: string | description: Email address associated with the external calendar account. Available only after completed successfully.  | validation: format EMAIL
     - name: status | type: Status | description: Connection status.  
         - enum:
         -     UNDEFINED: There is no information about the connection status.
         -     CONNECTED: The external calendar is connected to the Wix [schedule](https://dev.wix.com/docs/rest/business-management/calendar/schedules-v3/introduction.md), but the sync process hasn't started yet.
         -     SYNC_IN_PROGRESS: Sync process is ongoing.
         -     SYNCED: The Wix calendar and the external calendar are in sync.
         -     DISCONNECTED: The external calender has been disconnected from the Wix [schedule](https://dev.wix.com/docs/rest/business-management/calendar/schedules-v3/introduction.md).
         -     ERROR: The calendars sync is in error state.
     - name: errorReason | type: ErrorReason | description: Reason for the error. Available only if `status` is `ERROR`.  
         - enum:
         -     UNDEFINED: There is no information about the connection error.
         -     TOKEN_REVOKED: The external calendar's access token has been revoked.
         -     EXTERNAL_CALENDAR_CREATION_FAILED: The external calendar couldn't be created.
         -     EXTERNAL_CALENDAR_DELETED: The external calendar was deleted.
     - name: syncConfig | type: ConnectionSyncConfig | description: Settings about which sync operations are supported.  
        - name: listEventFromCalendars | type: ListEventFromCalendars | description: Configuration for importing events from the external calendar to the Wix site.  
           - ONE-OF: 
              - name: primaryCalendar | type: PrimaryCalendar | description: An empty `primaryCalendar` object indicates that you can import events only from the primary external calendar. Keep in mind that not all external calendar providers support primary calendars.  
       EMPTY-OBJECT {}
              - name: calendars | type: Calendars | description: You can import events from the list of specified external calendar accounts. The list may include the primary calendar.  
                 - name: calendars | type: array<Calendar> | description:   
                    - name: id | type: string | description: GUID of the external calendar account.  | read-only: true 
                    - name: name | type: string | description: Display name of the external calendar account. For example, `Primary` or `Birthdays`.  
           - name: enabled | type: boolean | description: Whether you can call [List Events](https://dev.wix.com/docs/rest/business-solutions/bookings/calendar/external-calendar-v2/list-events.md) to import events from the external calendar to the Wix site.  
        - name: syncToCalendar | type: SyncToCalendar | description: Configuration for exporting events from the Wix site to the external calendar.  
           - ONE-OF: 
              - name: primaryCalendar | type: PrimaryCalendar | description: An empty `primaryCalendar` object indicates that Wix events are exported only to the primary account of the external calendar.  
              - name: dedicatedCalendar | type: DedicatedCalendar | description: An empty `dedicatedCalendar` object indicates that Wix events are exported only to the dedicated account of the external calendar.  
       EMPTY-OBJECT {}
           - name: enabled | type: boolean | description: Whether Wix [events](https://dev.wix.com/docs/rest/business-management/calendar/events-v3/introduction.md) are exported to the external calendar.  

 Possible Errors:
   HTTP Code: 401 | Status Code: UNAUTHENTICATED | Application Code: BAD_CREDENTIALS | Description: The provided credentials are incorrect. Verify the email and password and try again.
   HTTP Code: 403 | Status Code: PERMISSION_DENIED | Application Code: PREMIUM_FEATURE_NOT_ENABLED | Description: This feature requires a premium plan. Upgrade to access external calendar integration.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: NOT_SUPPORTED_BY_PROVIDER | Description: The external calendar provider doesn't support this operation. Use a different connection method or provider.


```

### Examples

### Connect with an external calendar by credentials
```curl
curl -X POST 'https://www.wixapis.com/bookings/v2/external-calendars/connections:connectByCredentials' \
-H 'Authorization: <AUTH>' \
-H 'Content-Type: application/json' \
--data-raw '{
    "providerId": "9f084ae8-b3a6-4eb6-a29d-bc682c04b5fc",
    "scheduleId": "3e47ec65-2975-447c-a7ed-75041e850d5e",
    "email": "some@email.com",
    "password": "abcd-dcba-abcd-dcba"
}'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.bookings.externalCalendars.connectByCredentials(providerId, scheduleId, email, password)
 Description: Connects a [Wix schedule](https://dev.wix.com/docs/api-reference/business-management/calendar/schedules-v3/introduction.md) to an external calendar account using credentials.   ### Next steps  After connecting an external calendar account to a Wix schedule, you can do the following.  #### Check the 2-way-sync settings  Call [List Connections](https://dev.wix.com/docs/api-reference/business-solutions/bookings/calendar/external-calendar-v2/list-connections.md) and filter by the relevant schedule GUID.  If needed, call [Update Sync Config](https://dev.wix.com/docs/api-reference/business-solutions/bookings/calendar/external-calendar-v2/update-sync-config.md) to adjust the syncing configuration.  #### Retrieve external calendar events  Once a connection is successfully created, you can call [List Events](https://dev.wix.com/docs/api-reference/business-solutions/bookings/calendar/external-calendar-v2/list-events.md) to obtain an up-to-date list of events in the connected external calendars.  ### When to call Connect By OAuth instead  You could call [Connect By OAuth](https://dev.wix.com/docs/api-reference/business-solutions/bookings/calendar/external-calendar-v2/connect-by-o-auth.md) if:  + The external calendar provider doesn't support authorization by credentials. + You don't have access to the external calendar account credentials. + You want the account owner to approve the connection.  Call [List Providers](https://dev.wix.com/docs/api-reference/business-solutions/bookings/calendar/external-calendar-v2/list-providers.md) for a complete list of external calendar providers supported on the Wix site, including which authorization methods they support.
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  providerId, scheduleId, email, password
 Method parameters: 
   param name: providerId | type: string | description: GUID of the external calendar provider. Find this with the `listProviders()` function. | required: true | validation: format GUID
   param name: scheduleId | type: string | description: GUID of the schedule to connect with the external calendar account. | required: true | validation: format GUID
   param name: email | type: string | description: Email address for the external calendar account. | required: true | validation: format EMAIL
   param name: password | type: string | description: Password for the external calendar account. | required: true 
 Return type: PROMISE<ConnectByCredentialsResponse>
  - name: connection | type: Connection | description: Established connection details.  
     - name: _id | type: string | description: GUID of the connection between the external calendar and the Wix site.  
     - name: providerId | type: string | description: GUID of the external calendar provider.  | validation: format GUID
     - name: calendarType | type: CalendarType | description: External calendar type.  
         - enum:
         -     UNDEFINED: There is no information about the external calendar type.
         -     GOOGLE: [Google Calendar](https://developers.google.com/calendar/api/guides/overview).
         -     I_CAL: Apple iCalendar.
         -     OUTLOOK: __Deprecated__. Use `MICROSOFT` instead.
         -     OFFICE_365: __Deprecated__. Use `MICROSOFT` instead.
         -     MICROSOFT: Microsoft Calendar. For example, Office 365 calendar or Outlook calendar.
         -     OTHER: A different type of external calendar, not listed here.
     - name: scheduleId | type: string | description: GUID of the [schedule](https://dev.wix.com/docs/rest/business-management/calendar/schedules-v3/introduction.md) that's connected to the external calendar.  | validation: format GUID
     - name: userId | type: string | description: GUID of the [Wix user](https://dev.wix.com/docs/rest/articles/getting-started/about-identities.md#wix-user) to whom the external calendar connection belongs.  | validation: format GUID
     - name: appId | type: string | description: GUID of the app which created the external calendar connection.  | validation: format GUID
     - name: externalAccountEmail | type: string | description: Email address associated with the external calendar account. Available only after completed successfully.  | validation: format EMAIL
     - name: status | type: Status | description: Connection status.  
         - enum:
         -     UNDEFINED: There is no information about the connection status.
         -     CONNECTED: The external calendar is connected to the Wix [schedule](https://dev.wix.com/docs/rest/business-management/calendar/schedules-v3/introduction.md), but the sync process hasn't started yet.
         -     SYNC_IN_PROGRESS: Sync process is ongoing.
         -     SYNCED: The Wix calendar and the external calendar are in sync.
         -     DISCONNECTED: The external calender has been disconnected from the Wix [schedule](https://dev.wix.com/docs/rest/business-management/calendar/schedules-v3/introduction.md).
         -     ERROR: The calendars sync is in error state.
     - name: errorReason | type: ErrorReason | description: Reason for the error. Available only if `status` is `ERROR`.  
         - enum:
         -     UNDEFINED: There is no information about the connection error.
         -     TOKEN_REVOKED: The external calendar's access token has been revoked.
         -     EXTERNAL_CALENDAR_CREATION_FAILED: The external calendar couldn't be created.
         -     EXTERNAL_CALENDAR_DELETED: The external calendar was deleted.
     - name: syncConfig | type: ConnectionSyncConfig | description: Settings about which sync operations are supported.  
        - name: listEventFromCalendars | type: ListEventFromCalendars | description: Configuration for importing events from the external calendar to the Wix site.  
           - ONE-OF: 
              - name: calendars | type: Calendars | description: You can import events from the list of specified external calendar accounts. The list may include the primary calendar.  
                 - name: calendars | type: array<Calendar> | description:   
                    - name: _id | type: string | description: GUID of the external calendar account.  | read-only: true 
                    - name: name | type: string | description: Display name of the external calendar account. For example, `Primary` or `Birthdays`.  
           - name: enabled | type: boolean | description: Whether you can call [List Events](https://dev.wix.com/docs/rest/business-solutions/bookings/calendar/external-calendar-v2/list-events.md) to import events from the external calendar to the Wix site.  
        - name: syncToCalendar | type: SyncToCalendar | description: Configuration for exporting events from the Wix site to the external calendar.  
           - name: enabled | type: boolean | description: Whether Wix [events](https://dev.wix.com/docs/rest/business-management/calendar/events-v3/introduction.md) are exported to the external calendar.  

 Possible Errors:
   HTTP Code: 401 | Status Code: UNAUTHENTICATED | Application Code: BAD_CREDENTIALS | Description: The provided credentials are incorrect. Verify the email and password and try again.
   HTTP Code: 403 | Status Code: PERMISSION_DENIED | Application Code: PREMIUM_FEATURE_NOT_ENABLED | Description: This feature requires a premium plan. Upgrade to access external calendar integration.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: NOT_SUPPORTED_BY_PROVIDER | Description: The external calendar provider doesn't support this operation. Use a different connection method or provider.


```

### Examples

### connectByCredentials
```javascript
import { externalCalendars } from '@wix/bookings';

async function connectByCredentials(providerId,scheduleId,email,password) {
  const response = await externalCalendars.connectByCredentials(providerId,scheduleId,email,password);
};
```

### connectByCredentials (with elevated permissions)
```javascript
import { externalCalendars } from '@wix/bookings';
import { auth } from '@wix/essentials';

async function myConnectByCredentialsMethod(providerId,scheduleId,email,password) {
  const elevatedConnectByCredentials = auth.elevate(externalCalendars.connectByCredentials);
  const response = await elevatedConnectByCredentials(providerId,scheduleId,email,password);
}
```

### connectByCredentials (self-managed)
Self-managed SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { externalCalendars } from '@wix/bookings';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { externalCalendars },
  // Include the auth strategy and host as relevant
});


async function connectByCredentials(providerId,scheduleId,email,password) {
  const response = await myWixClient.externalCalendars.connectByCredentials(providerId,scheduleId,email,password);
};
```

---