> 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

## Resource: Sample Flows

## Article: Sample Flows

## Article Link: https://dev.wix.com/docs/api-reference/business-management/seo/bing-webmaster-tools/connection-v1/sample-flows.md

## Article Content:

# BWT Connection: Sample Flows

This article presents possible use cases and corresponding sample flows that you can support. It provides a useful starting point as you plan your implementation.

## Connect a site to Bing Webmaster Tools

A Wix user wants their site connected to Bing Webmaster Tools so it can be added, verified, and submit its sitemap. Your app runs the authorization and waits for it to complete.

To connect a site:

1. Call [Get Connection](https://dev.wix.com/docs/api-reference/business-management/seo/bing-webmaster-tools/connection-v1/get-connection.md) to check the starting point. `VALID` means only that stored credentials exist: Microsoft can revoke them without Get Connection noticing. So when `status` is `VALID`, also call [Get Site Readiness](https://dev.wix.com/docs/api-reference/business-management/seo/bing-webmaster-tools/site-readiness-v1/get-site-readiness.md). If its `blockingReason` isn't `NOT_CONNECTED`, the connection works: skip the remaining steps and continue with the [BWT Site Readiness API](https://dev.wix.com/docs/api-reference/business-management/seo/bing-webmaster-tools/site-readiness-v1/introduction.md), unless the Wix user wants a different Microsoft account. Don't call Get Connect URL for a working connection: authorizing with the same Microsoft account only refreshes its credentials, but authorizing with a different one replaces the connected account.
1. If `status` is `VALID` or `INVALID` and you're reconnecting, for example because Get Site Readiness reports `NOT_CONNECTED` or the Wix user wants a different Microsoft account, call [Disconnect](https://dev.wix.com/docs/api-reference/business-management/seo/bing-webmaster-tools/connection-v1/disconnect.md) first. While stored credentials exist, neither Get Connection nor Get Site Readiness reports when a new authorization finishes, so a reconnect without Disconnect can't be followed. After Disconnect, `status` is `NOT_CONNECTED`.
1. Call [Get Connect URL](https://dev.wix.com/docs/api-reference/business-management/seo/bing-webmaster-tools/connection-v1/get-connect-url.md) and store the returned `connectUrl`. If the call fails with `FAILED_PRECONDITION`, resolve the reported problem first: publish the site, connect a domain, or allow search-engine indexing.
1. Open `connectUrl` for the person connecting in a new browser tab or a top-level window. Don't open it in a popup that keeps a reference to your page. The URL is single-use and expires after 2 hours, so request a fresh one for every attempt.
1. Poll [Get Connection](https://dev.wix.com/docs/api-reference/business-management/seo/bing-webmaster-tools/connection-v1/get-connection.md) every few seconds. `status` is `PENDING` while the person authorizes, and becomes `VALID` when the exchange completes. If it goes back to `NOT_CONNECTED`, the person declined or the authorization failed, so stop and offer to try again.
1. Stop polling if the attempt hasn't completed 10 minutes after you opened `connectUrl`: the person must finish on Bing within that window. Request a fresh URL to try again. An abandoned attempt can keep reporting `PENDING` for up to 2 hours, so don't wait for it to change on its own.
1. Continue with the [BWT Site Readiness API](https://dev.wix.com/docs/api-reference/business-management/seo/bing-webmaster-tools/site-readiness-v1/introduction.md) to add and verify the site.

## Show the site's connection status

Your app has a settings page that shows whether the site is connected to Bing Webmaster Tools, and offers the right action for the current state.

To show the connection status:

1. Call [Get Connection](https://dev.wix.com/docs/api-reference/business-management/seo/bing-webmaster-tools/connection-v1/get-connection.md).
1. Present the returned `status`. For `VALID`, show the site as connected, after checking that [Get Site Readiness](https://dev.wix.com/docs/api-reference/business-management/seo/bing-webmaster-tools/site-readiness-v1/get-site-readiness.md) doesn't report `NOT_CONNECTED`. If it does, offer to reconnect. For `INVALID`, tell the Wix user the connection stopped working and offer to reconnect. To reconnect, call [Disconnect](https://dev.wix.com/docs/api-reference/business-management/seo/bing-webmaster-tools/connection-v1/disconnect.md) first, then follow [Connect a site to Bing Webmaster Tools](#connect-a-site-to-bing-webmaster-tools). For `PENDING`, show that an authorization was started and hasn't completed. It can stay `PENDING` for up to 2 hours after an attempt is abandoned, so offer to start a new one. For `NOT_CONNECTED`, offer to connect.
1. Use `ownedByCaller` only when `status` is `VALID` or `INVALID`. When it's `false`, the current caller doesn't own the connection, so offer to replace it with care rather than presenting it as theirs. Don't read `false` as proof that a specific other Wix user connected the account.

## Disconnect a Microsoft account

A Wix user wants Wix to stop using their Microsoft account for this site, for example before handing the site over to someone else.

Disconnecting removes only this site's connection. Other sites connected with the same Microsoft account stay connected, and an authorization attempt still in progress for this site is cancelled. It doesn't remove the site's `msvalidate.01` tag (use [Clear Verification](https://dev.wix.com/docs/api-reference/business-management/seo/bing-webmaster-tools/site-readiness-v1/clear-verification.md) in the BWT Site Readiness API for that), doesn't change anything in the Bing account, and doesn't revoke Wix's access on Microsoft's side. The account owner can revoke it from their Microsoft account settings.

To disconnect a site:

1. Call [Get Connection](https://dev.wix.com/docs/api-reference/business-management/seo/bing-webmaster-tools/connection-v1/get-connection.md) to confirm the site is connected.
1. Call [Disconnect](https://dev.wix.com/docs/api-reference/business-management/seo/bing-webmaster-tools/connection-v1/disconnect.md). A `NOT_FOUND` (`CONNECTION_NOT_FOUND`) error means the site has no stored credentials, so there's nothing to disconnect. An `UNAVAILABLE` (`BWT_SITE_BUSY`) error means another Bing Webmaster Tools operation is running on the site, so retry.
1. Call [Get Connection](https://dev.wix.com/docs/api-reference/business-management/seo/bing-webmaster-tools/connection-v1/get-connection.md) again to confirm `status` is `NOT_CONNECTED`.