> ## Documentation Index
> Fetch the complete documentation index at: https://docs.searchcompany.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Overview

> Technical overview of the Mark Step Complete endpoint

# POST /api/domain/mark-step-complete/{org_id}

Marks a connection step as complete after Entri confirms DNS records were added successfully.

## Purpose

This endpoint is called by the frontend after Entri confirms successful DNS configuration:

* **Step 1:** SSL CNAME added → status becomes `SSL_VALIDATING`
* **Step 2:** www CNAME switched → status becomes `DEPLOYED` + triggers background tasks

## Architecture

```mermaid theme={null}
flowchart TD
    A[Entri Success Callback] --> B[Mark Step Complete]
    B --> C{Which Step?}
    C -->|Step 1| D[Update: SSL_VALIDATING]
    D --> E[Return Success]
    C -->|Step 2| F[Update: DEPLOYED]
    F --> G[Set deployed_at timestamp]
    G --> H[Trigger Background Tasks]
    H --> I[Return Success]
    
    subgraph bg [Background Tasks]
        J[ACM Certificate Upgrade]
        K[Google Verify + Submit Flow]
    end
    H --> J
    H --> K
    
    subgraph verify [Google Verify + Submit Flow]
        L[Poll Google Verification<br/>10s × 12 = 2 min]
        L --> M{Verified?}
        M -->|Yes| N[IndexNow Submission]
        M -->|Yes| O[GSC Sitemap Submission]
        M -->|No after 2 min| P[IndexNow Only]
    end
```

## Internal Services

### \_background\_acm\_upgrade

Upgrades from Let's Encrypt certificate to ACM-native certificate for auto-renewal.

**Triggered:** After Step 2 completes (60 second delay)

**Location:** `src/app/apis/domain/mark_step_complete/routes.py`

### \_background\_google\_verify\_and\_submit

Orchestrates Google verification polling, then triggers search engine submissions.

**Triggered:** After Step 2 completes

**Flow:**

1. Poll Google verification every 10 seconds for 2 minutes (12 attempts)
2. Once verified → update DB status to "VERIFIED"
3. Add site to Google Search Console
4. Run IndexNow submission (always, regardless of Google verification)
5. Run GSC sitemap submission (only if Google verified)

**Location:** `src/app/apis/domain/mark_step_complete/routes.py`

### \_background\_indexnow\_submission

Submits all AI site URLs to IndexNow for search engine indexing.

**Triggered:** By `_background_google_verify_and_submit` after polling completes

**Location:** `src/app/apis/domain/mark_step_complete/routes.py`

### \_background\_gsc\_submission

Submits sitemap to Google Search Console.

**Triggered:** By `_background_google_verify_and_submit` only if Google verification succeeds

**Location:** `src/app/apis/domain/mark_step_complete/routes.py`

## Request Body

| Field  | Type    | Description |
| ------ | ------- | ----------- |
| `step` | integer | 1 or 2      |

## Response Fields

| Field          | Type   | Description                              |
| -------------- | ------ | ---------------------------------------- |
| `status`       | string | "success"                                |
| `proxy_status` | string | New status (SSL\_VALIDATING or DEPLOYED) |

## Background Task Details

### ACM Upgrade

* Waits 60 seconds before starting
* Requests new ACM certificate with DNS validation
* ACM certificates auto-renew (unlike Let's Encrypt)
* User doesn't wait for this

### Google Verification + Search Engine Submission

* Polls Google verification every 10 seconds for up to 2 minutes
* This gives DNS time to propagate after user adds TXT record in Step 1
* IndexNow runs regardless of Google verification result
* GSC sitemap only submits if Google verification succeeds

## Why Poll in Step 2?

The Google TXT record is added during Step 1 (via Entri), but verification is checked in Step 2 because:

1. **DNS Propagation Time**: TXT records need time to propagate globally
2. **More Time**: By Step 2, the TXT record has had time to propagate
3. **Resilience**: Polling handles slow DNS propagation gracefully
4. **Non-blocking**: User doesn't wait - it runs in background

## Code Location

```
src/app/apis/domain/mark_step_complete/routes.py
```
