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

# Create mirror

```http theme={null}
POST api/v1/flows/cdc/create
```

This endpoint is used to create a CDC mirror.

### Request Fields

<ParamField path="connection_configs" type="object" required>
  Connection configuration
</ParamField>

<Expandable title="connection_configs">
  <ParamField path="flow_job_name" type="string" required>
    The name of the mirror to be created.
  </ParamField>

  <ParamField path="source_name" type="string" required>
    The name of the source peer (data store).
  </ParamField>

  <ParamField path="destination_name" type="string" required>
    The name of the destination peer (data store).
  </ParamField>

  <ParamField path="table_mappings" type="array" required>
    Table mappings
  </ParamField>

  <Expandable title="table_mappings">
    <ParamField path="source_table_identifier" type="string" required>
      The source table identifier.
    </ParamField>

    <ParamField path="destination_table_identifier" type="string" required>
      The destination table identifier.
    </ParamField>

    <ParamField path="exclude" type="string">
      Columns from the source table to exclude, separated by commas.
    </ParamField>

    <ParamField path="columns" type="object">
      **For Clickhouse Only And Optional**. Ordering key setting for Clickhouse target tables created by PeerDB.
    </ParamField>

    <Expandable title="columns">
      <ParamField path="sourceName" type="string" required>
        Name of the column
      </ParamField>

      <ParamField path="ordering" type="number">
        A number indicating the rank of this column in the ordering key of ORDER BY in ReplacingMergeTree.
      </ParamField>
    </Expandable>
  </Expandable>

  <ParamField path="do_initial_snapshot" type="boolean" required>
    Whether to do an initial snapshot.
  </ParamField>

  <ParamField path="max_batch_size" type="number" default="1000000">
    The maximum number of rows to sync in a batch.
  </ParamField>

  <ParamField path="idle_timeout_seconds" type="number" default="60">
    How often the mirror syncs, in seconds.
  </ParamField>

  <ParamField path="publication_name" type="string">
    The name of the publication to use. PeerDB will try to create a publication if not provided here.
  </ParamField>

  <ParamField path="snapshot_num_rows_per_partition" type="number" default="1000000">
    The number of rows per partition to sync during the initial snapshot.
    Default is 1 million rows.
  </ParamField>

  <ParamField path="snapshot_max_parallel_workers" type="number" default="4">
    The maximum number of parallel workers to use during the initial snapshot.
  </ParamField>

  <ParamField path="snapshot_num_tables_in_parallel" type="number" default="1">
    The number of tables to sync in parallel during the initial snapshot.
  </ParamField>

  <ParamField path="resync" type="boolean" default="false">
    Whether to resync the mirror. The mirror **must be dropped** before resyncing.
  </ParamField>

  <ParamField path="initial_snapshot_only" type="boolean" default="false">
    Whether to do only the initial snapshot and not perform CDC.
  </ParamField>

  <ParamField path="soft_delete_col_name" type="string">
    The name of the column that indicates a soft delete.
  </ParamField>

  <ParamField path="synced_at_col_name" type="string">
    The name of the column that indicates when the row was last synced.
  </ParamField>
</Expandable>

### Response Fields

<ParamField path="workflowId" type="string">
  The ID of the parent workflow created for this mirror.
</ParamField>

<RequestExample>
  ```bash Request theme={null}
  curl --request POST \
    --url localhost:3000/api/v1/flows/cdc/create \
    --header 'Authorization: Basic OnJsYWNrd3dhbmEyMw==' \
    --header 'Content-Type: application/json' \
    --data '
  {
  "connection_configs": {
    "flow_job_name": "mirror_api_kick_off",
  	 "source_name": "rds_peer",
    "destination_name": "ch_peer",
    "table_mappings": [
      {
        "source_table_identifier": "public.users",
        "destination_table_identifier": "users_api"
      },
      {
        "source_table_identifier": "public.payments",
        "destination_table_identifier": "payments_api"
      },
      {
        "source_table_identifier": "public.optional_ordering_key",
        "destination_table_identifier": "optional_ordering_key",
        "columns": [
          {
            "sourceName": "id",
            "ordering": 1
          },
          {
            "sourceName": "created_at",
            "ordering": 2
          }
        ]
      },
    ],
    "max_batch_size": 1000,
    "idle_timeout_seconds": 300,
    "publication_name": "",
    "do_initial_snapshot": true,
    "snapshot_num_rows_per_partition": 5000,
    "snapshot_max_parallel_workers": 4,
    "snapshot_num_tables_in_parallel": 2,
    "resync": false,
    "initial_snapshot_only": false,
    "soft_delete_col_name": "_peerdb_is_deleted",
    "synced_at_col_name": "_peerdb_synced_at"
  }
  }'
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
  	"workflowId": "mirror_kick_off-peerflow-2d269226-9757-4d9f-8cfd-6adb1ca29c0e"
  }
  ```

  ```json Error example theme={null}
  {
  	"code": 2,
  	"message": "invalid mirror: mirror with name mirror_api_kick_off already exists",
  	"details": []
  }
  ```
</ResponseExample>
