{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/robosystems-ai/json-schema/robosystems-ai-create-connection-request-schema.json",
  "title": "CreateConnectionRequest",
  "description": "Request to create a new connection.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/robosystems-ai-connections-api-openapi.yml#/components/schemas/CreateConnectionRequest",
  "properties": {
    "provider": {
      "type": "string",
      "enum": [
        "quickbooks",
        "external",
        "mercury",
        "plaid"
      ],
      "title": "Provider",
      "description": "Connection provider type"
    },
    "entity_id": {
      "anyOf": [
        {
          "type": "string",
          "minLength": 1
        },
        {
          "type": "null"
        }
      ],
      "title": "Entity Id",
      "description": "QuickBooks: the entity whose books it keeps, which can only be the group parent; omit it. A bank feed names its entity on its own config."
    },
    "quickbooks_config": {
      "anyOf": [
        {
          "$ref": "#/$defs/QuickBooksConnectionConfig"
        },
        {
          "type": "null"
        }
      ]
    },
    "external_config": {
      "anyOf": [
        {
          "$ref": "#/$defs/ExternalConnectionConfig"
        },
        {
          "type": "null"
        }
      ]
    },
    "mercury_config": {
      "anyOf": [
        {
          "$ref": "#/$defs/MercuryConnectionConfig"
        },
        {
          "type": "null"
        }
      ]
    },
    "plaid_config": {
      "anyOf": [
        {
          "$ref": "#/$defs/PlaidConnectionConfig"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "type": "object",
  "required": [
    "provider"
  ],
  "$defs": {
    "ExternalConnectionConfig": {
      "properties": {
        "source_name": {
          "type": "string",
          "maxLength": 64,
          "minLength": 2,
          "pattern": "^[a-z][a-z0-9_-]{1,63}$",
          "title": "Source Name",
          "description": "Source slug the integration stamps on the events it emits (lowercase letters, digits, '-', '_'; must start with a letter). Unique per graph among live connections."
        },
        "display_name": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 128
            },
            {
              "type": "null"
            }
          ],
          "title": "Display Name",
          "description": "Human-readable label for the connections UI."
        }
      },
      "type": "object",
      "required": [
        "source_name"
      ],
      "title": "ExternalConnectionConfig",
      "description": "External-integration connection configuration.\n\nRegisters a source namespace for an integration the platform does not\nrun: the connection is registration + telemetry, not execution config.\nThe platform holds no credentials for the external source — the\nintegration authenticates to its own source and writes here through\nthe public API, stamping `source_name` on everything it emits."
    },
    "MercuryConnectionConfig": {
      "properties": {
        "since_date": {
          "anyOf": [
            {
              "type": "string",
              "format": "date"
            },
            {
              "type": "null"
            }
          ],
          "title": "Since Date",
          "description": "First day of the backfill (ISO 8601). Defaults to two years back. Incremental syncs never look back before it, and lines dated in a closed period are never captured."
        },
        "include_treasury": {
          "type": "boolean",
          "title": "Include Treasury",
          "description": "Capture treasury-account activity alongside checking/savings.",
          "default": true
        },
        "api_key": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 8
            },
            {
              "type": "null"
            }
          ],
          "title": "Api Key",
          "description": "A personal read-only Mercury API token, for deployments that allow the api_key credential mode. Omit to connect over OAuth."
        },
        "entity_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Entity Id",
          "description": "The entity whose books the feed's accounts land on: a subsidiary's id, or omit for the group parent. Required when QuickBooks keeps the parent's books. Each account can be moved to another entity later with `link-bank-account`."
        }
      },
      "type": "object",
      "title": "MercuryConnectionConfig",
      "description": "Mercury bank-feed connection configuration.\n\nA bank feed is native accounting: the entity its accounts land on must\nalready have a chart of accounts and must not be the one QuickBooks keeps\n(the group parent, while QuickBooks is connected). Over OAuth (the hosted\ndefault) the connection is created `pending_oauth` and activated by the\ncallback. `api_key` — a personal **read-only** Mercury token — connects\nat once without a browser round-trip, but only on deployments that turn\non `MERCURY_API_KEY_CONNECTIONS_ENABLED` (self-hosted and local); the\nhosted product refuses it."
    },
    "PlaidConnectionConfig": {
      "properties": {
        "since_date": {
          "anyOf": [
            {
              "type": "string",
              "format": "date"
            },
            {
              "type": "null"
            }
          ],
          "title": "Since Date",
          "description": "First day of the backfill (ISO 8601), and how much history Plaid is asked to pull for the new Item (at most two years). Defaults to as far back as Plaid goes. Lines dated in a closed period are never captured, whatever the window."
        },
        "entity_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Entity Id",
          "description": "The entity whose books the feed's accounts land on: a subsidiary's id, or omit for the group parent. Required when QuickBooks keeps the parent's books. Each account can be moved to another entity later with `link-bank-account`."
        }
      },
      "type": "object",
      "title": "PlaidConnectionConfig",
      "description": "Plaid bank-feed connection configuration.\n\nA bank feed is native accounting: the entity its accounts land on must\nalready have a chart of accounts and must not be the one QuickBooks keeps\n(the group parent, while QuickBooks is connected). The connection is\ncreated `pending_oauth`; `POST /oauth/init` returns a `link_token` for\nPlaid Link, and the `public_token` Link hands back completes it through\n`POST /oauth/callback/plaid` (as `code`). One connection per institution\nlogin; a graph can hold several."
    },
    "QuickBooksConnectionConfig": {
      "properties": {
        "realm_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Realm Id",
          "description": "QuickBooks Realm ID"
        },
        "refresh_token": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Refresh Token",
          "description": "OAuth refresh token"
        }
      },
      "type": "object",
      "title": "QuickBooksConnectionConfig",
      "description": "QuickBooks-specific connection configuration."
    }
  }
}