> 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: googleSearchConsole

# Namespace: GscConnectionService

# Method link: https://dev.wix.com/docs/api-reference/business-management/seo/google-search-console/connection-v1/get-connect-url.md

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

## Introduction

Retrieves the Google authorization URL for the Wix user to open.

Surface the returned URL to the person connecting. After they authorize in
their browser, Wix completes the OAuth exchange server-side. There is no
code-exchange call to make. Poll Get Connection until the status is
`VALID`.

Any Google account can be used and needs no prior Search Console setup.
Site verification and property access are established afterwards through
the GSC 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.

Any user with SEO permissions can start a connection, not only the site
owner. The resulting connection is owned by the calling user; Get
Connection reports whether the current caller is that owner.

An already-connected site may call this too. Authorizing again with the
same Google account refreshes the stored credentials, and authorizing with
a different one replaces the connection.

Requires the site to be published, have a connected domain, and allow
search-engine indexing; otherwise fails with `FAILED_PRECONDITION`. These
are a subset of what the SEO dashboard checks before it offers the flow.
The dashboard also blocks on unpublished changes, on a site the caller
lacks permission to publish or to connect a domain for, and on a
non-indexable homepage.

---

## REST API

### Schema

```
 Method: getConnectUrl
 Description: Retrieves the Google authorization URL for the Wix user to open.  Surface the returned URL to the person connecting. After they authorize in their browser, Wix completes the OAuth exchange server-side. There is no code-exchange call to make. Poll Get Connection until the status is `VALID`.  Any Google account can be used and needs no prior Search Console setup. Site verification and property access are established afterwards through the GSC 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.  Any user with SEO permissions can start a connection, not only the site owner. The resulting connection is owned by the calling user; Get Connection reports whether the current caller is that owner.  An already-connected site may call this too. Authorizing again with the same Google account refreshes the stored credentials, and authorizing with a different one replaces the connection.  Requires the site to be published, have a connected domain, and allow search-engine indexing; otherwise fails with `FAILED_PRECONDITION`. These are a subset of what the SEO dashboard checks before it offers the flow. The dashboard also blocks on unpublished changes, on a site the caller lacks permission to publish or to connect a domain for, and on a non-indexable homepage.
 URL: https://www.wixapis.com/gsc/connection/v1/connect-url
 Method: GET
 Return type: GetConnectUrlResponse
  - name: connectUrl | type: string | description: URL the connecting person opens to authorize Wix to access their Google Search Console 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: GSC_CONSENT_URL_MISSING_IDENTITY | Description: The caller has no resolvable 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: GSC_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/gsc/connection/v1/connect-url' \
-H 'Authorization: <AUTH>'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.gsc.connection.getConnectUrl()
 Description: Retrieves the Google authorization URL for the Wix user to open.  Surface the returned URL to the person connecting. After they authorize in their browser, Wix completes the OAuth exchange server-side. There is no code-exchange call to make. Poll Get Connection until the status is `VALID`.  Any Google account can be used and needs no prior Search Console setup. Site verification and property access are established afterwards through the GSC 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.  Any user with SEO permissions can start a connection, not only the site owner. The resulting connection is owned by the calling user; Get Connection reports whether the current caller is that owner.  An already-connected site may call this too. Authorizing again with the same Google account refreshes the stored credentials, and authorizing with a different one replaces the connection.  Requires the site to be published, have a connected domain, and allow search-engine indexing; otherwise fails with `FAILED_PRECONDITION`. These are a subset of what the SEO dashboard checks before it offers the flow. The dashboard also blocks on unpublished changes, on a site the caller lacks permission to publish or to connect a domain for, and on a non-indexable homepage.
 Return type: PROMISE<GetConnectUrlResponse>
  - name: connectUrl | type: string | description: URL the connecting person opens to authorize Wix to access their Google Search Console 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: GSC_CONSENT_URL_MISSING_IDENTITY | Description: The caller has no resolvable 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: GSC_CALLBACK_URL_NOT_CONFIGURED | Description: The server-side connect flow is not enabled on this environment.


```

### Examples

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

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

/* Promise resolves to:
 * {
 *   "connectUrl": "https://accounts.google.com/o/oauth2/v2/auth?client_id=407408718192.apps.googleusercontent.com&redirect_uri=https%3A%2F%2Fwww.wixapis.com%2Fgsc%2Fconnection%2Fv1%2Fconnect-callback&response_type=code&scope=openid%20email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fwebmasters&state=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/gsc';
// 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();
};
```

---