> 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`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# GetConnectUrl

# Package: bingWebmasterTools

# Namespace: BwtConnectionService

# Method link: https://dev.wix.com/docs/api-reference/business-management/seo/bing-webmaster-tools/connection-v1/get-connect-url.md

## Permission Scopes:
Manage SEO Settings: SCOPE.PROMOTE.MANAGE-SEO

## Introduction

Retrieves the connect URL for the Wix user to open.

Surface the returned URL to the person connecting. It opens a Wix page
that sends them on to Bing to authorize. Open it in a top-level browser
window or tab, not in a popup that keeps a reference to the page that
opened it. After they authorize, Wix completes the OAuth exchange
server-side. There is no code-exchange call to make. Poll Get Connection
until the status is `VALID`.

Any Microsoft account can be used. Adding and verifying the site in Bing
Webmaster Tools happen afterwards through the BWT Site Readiness API.

Each call starts a new authorization attempt: the returned URL is
single-use and expires after 2 hours, so request a fresh one for every
attempt rather than caching or reusing one. The person must finish on
Bing within 10 minutes of opening the URL, in the same browser, while
signed in to Wix as the user who called this method.

Only a Wix user can start a connection: the connection is owned by the
calling user, and a caller with no user identity, such as an app or an
API key, fails with `PERMISSION_DENIED`. Any user with SEO permissions
can start one, not only the site owner. Get Connection reports whether
the current caller is the owner.

An already-connected site may call this too. Authorizing again with the
same Bing account refreshes the stored credentials, and authorizing with
a different one replaces the connection. While stored credentials exist,
neither Get Connection nor Get Site Readiness reports when the new
authorization finishes. To follow a reconnect, call Disconnect first:
Get Connection then reports `PENDING` until it reports `VALID`.

Requires the site to be published, have a connected domain, and allow
search-engine indexing; otherwise fails with `FAILED_PRECONDITION`.

---

## REST API

### Schema

```
 Method: getConnectUrl
 Description: Retrieves the connect URL for the Wix user to open.  Surface the returned URL to the person connecting. It opens a Wix page that sends them on to Bing to authorize. Open it in a top-level browser window or tab, not in a popup that keeps a reference to the page that opened it. After they authorize, Wix completes the OAuth exchange server-side. There is no code-exchange call to make. Poll Get Connection until the status is `VALID`.  Any Microsoft account can be used. Adding and verifying the site in Bing Webmaster Tools happen afterwards through the BWT Site Readiness API.  Each call starts a new authorization attempt: the returned URL is single-use and expires after 2 hours, so request a fresh one for every attempt rather than caching or reusing one. The person must finish on Bing within 10 minutes of opening the URL, in the same browser, while signed in to Wix as the user who called this method.  Only a Wix user can start a connection: the connection is owned by the calling user, and a caller with no user identity, such as an app or an API key, fails with `PERMISSION_DENIED`. Any user with SEO permissions can start one, not only the site owner. Get Connection reports whether the current caller is the owner.  An already-connected site may call this too. Authorizing again with the same Bing account refreshes the stored credentials, and authorizing with a different one replaces the connection. While stored credentials exist, neither Get Connection nor Get Site Readiness reports when the new authorization finishes. To follow a reconnect, call Disconnect first: Get Connection then reports `PENDING` until it reports `VALID`.  Requires the site to be published, have a connected domain, and allow search-engine indexing; otherwise fails with `FAILED_PRECONDITION`.
 URL: https://www.wixapis.com/gsc/connection/v1/bing/connect-url
 Method: GET
 Return type: GetConnectUrlResponse
  - name: connectUrl | type: string | description: URL the connecting person opens to authorize Wix to access their Bing Webmaster Tools data. Single-use and short-lived; request a new one for each attempt.  | validation: format SECURE_WEB_URL

 Possible Errors:
   HTTP Code: 403 | Status Code: PERMISSION_DENIED | Application Code: BWT_CONNECT_URL_MISSING_IDENTITY | Description: The caller has no resolvable Wix user identity to own the connection.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: SITE_NOT_INDEXABLE | Description: The site does not allow search-engine indexing.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: DOMAIN_NOT_CONNECTED | Description: The site has no connected domain.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: SITE_NOT_PUBLISHED | Description: The site is not published.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: SITE_NOT_RESOLVED | Description: The site could not be resolved from the request context.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: BWT_CALLBACK_URL_NOT_CONFIGURED | Description: The server-side connect flow is not enabled on this environment.


```

### Examples

### Get Connect URL
```curl
curl -X GET \
'https://www.wixapis.com/bwt/connection/v1/bing/connect-url' \
-H 'Authorization: <AUTH>'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.bwt.connection.getConnectUrl()
 Description: Retrieves the connect URL for the Wix user to open.  Surface the returned URL to the person connecting. It opens a Wix page that sends them on to Bing to authorize. Open it in a top-level browser window or tab, not in a popup that keeps a reference to the page that opened it. After they authorize, Wix completes the OAuth exchange server-side. There is no code-exchange call to make. Poll Get Connection until the status is `VALID`.  Any Microsoft account can be used. Adding and verifying the site in Bing Webmaster Tools happen afterwards through the BWT Site Readiness API.  Each call starts a new authorization attempt: the returned URL is single-use and expires after 2 hours, so request a fresh one for every attempt rather than caching or reusing one. The person must finish on Bing within 10 minutes of opening the URL, in the same browser, while signed in to Wix as the user who called this method.  Only a Wix user can start a connection: the connection is owned by the calling user, and a caller with no user identity, such as an app or an API key, fails with `PERMISSION_DENIED`. Any user with SEO permissions can start one, not only the site owner. Get Connection reports whether the current caller is the owner.  An already-connected site may call this too. Authorizing again with the same Bing account refreshes the stored credentials, and authorizing with a different one replaces the connection. While stored credentials exist, neither Get Connection nor Get Site Readiness reports when the new authorization finishes. To follow a reconnect, call Disconnect first: Get Connection then reports `PENDING` until it reports `VALID`.  Requires the site to be published, have a connected domain, and allow search-engine indexing; otherwise fails with `FAILED_PRECONDITION`.
 Return type: PROMISE<GetConnectUrlResponse>
  - name: connectUrl | type: string | description: URL the connecting person opens to authorize Wix to access their Bing Webmaster Tools data. Single-use and short-lived; request a new one for each attempt.  | validation: format SECURE_WEB_URL

 Possible Errors:
   HTTP Code: 403 | Status Code: PERMISSION_DENIED | Application Code: BWT_CONNECT_URL_MISSING_IDENTITY | Description: The caller has no resolvable Wix user identity to own the connection.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: SITE_NOT_INDEXABLE | Description: The site does not allow search-engine indexing.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: DOMAIN_NOT_CONNECTED | Description: The site has no connected domain.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: SITE_NOT_PUBLISHED | Description: The site is not published.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: SITE_NOT_RESOLVED | Description: The site could not be resolved from the request context.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: BWT_CALLBACK_URL_NOT_CONFIGURED | Description: The server-side connect flow is not enabled on this environment.


```

### Examples

### Get a Bing authorization URL for connecting the site
```javascript
import { connection } from "@wix/bwt";

async function getConnectUrl() {
  const response = await connection.getConnectUrl();
}

/* Promise resolves to:
 * {
 *   "connectUrl": "https://manage.wix.com/_serverless/seo-serverless/bwt-connect-start?s=Zk3q8vXbW1dYcT5nR7pLmA2sE9uH4jK0fG6iN8oB3xw"
 * }
 */

```

### getConnectUrl (self-hosted)
Self-hosted 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 { connection } from '@wix/bwt';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

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


async function getConnectUrl() {
  const response = await myWixClient.connection.getConnectUrl();
};
```

---