{
  "openapi": "3.1.0",
  "info": {
    "title": "KeyGuardRail Inventory Integrations",
    "version": "1.1.0",
    "description": "Metadata only. Never submit secrets. HTTPS required. Integration credentials expire and can be revoked. Generic, customer-side collector and EventBridge delivery use integration credentials; Azure and Google native events require their provider JWTs. See the in-app integration guide for source binding, scopes, retention, evidence policy and provider setup."
  },
  "servers": [
    {
      "url": "https://keyguardrail.com"
    }
  ],
  "paths": {
    "/api/v1/integrations/{organizationId}/{integrationId}/events": {
      "parameters": [
        {
          "name": "organizationId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "integrationId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "receiveEvent",
        "summary": "Receive generic or native provider event",
        "description": "Required scope: events:write.",
        "security": [
          {
            "integrationBearer": []
          },
          {
            "eventBridgeKey": []
          },
          {
            "providerJWT": []
          }
        ],
        "responses": {
          "202": {
            "description": "Accepted durably; query processing status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EventReceipt"
                }
              }
            }
          },
          "400": {
            "description": "Invalid metadata or source",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope, disabled integration or read-only workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in this integration",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflicting mapping, event ID or idempotency key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Payload exceeds 64 KiB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "JSON required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit; honor Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporary storage or verification failure",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "200": {
            "description": "Authenticated Azure subscription validation only. This does not verify delivery.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "validationResponse": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/GenericEvent"
                  },
                  {
                    "$ref": "#/components/schemas/AWS"
                  },
                  {
                    "$ref": "#/components/schemas/AzureBatch"
                  },
                  {
                    "$ref": "#/components/schemas/GooglePush"
                  },
                  {
                    "$ref": "#/components/schemas/VaultCollector"
                  },
                  {
                    "$ref": "#/components/schemas/OnePasswordCollector"
                  },
                  {
                    "$ref": "#/components/schemas/BitwardenCollector"
                  }
                ]
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listEvents",
        "summary": "List up to 100 events; follow nextCursor",
        "description": "Required scope: status:read.",
        "security": [
          {
            "integrationBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid metadata or source",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope, disabled integration or read-only workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in this integration",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflicting mapping, event ID or idempotency key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Payload exceeds 64 KiB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "JSON required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit; honor Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporary storage or verification failure",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 300
            }
          }
        ]
      }
    },
    "/api/v1/integrations/{organizationId}/{integrationId}/events/{id}": {
      "parameters": [
        {
          "name": "organizationId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "integrationId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getEvent",
        "summary": "Get event processing outcome",
        "description": "Required scope: status:read.",
        "security": [
          {
            "integrationBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid metadata or source",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope, disabled integration or read-only workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in this integration",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflicting mapping, event ID or idempotency key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Payload exceeds 64 KiB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "JSON required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit; honor Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporary storage or verification failure",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/integrations/{organizationId}/{integrationId}/status": {
      "parameters": [
        {
          "name": "organizationId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "integrationId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getIntegrationStatus",
        "summary": "Get delivery and reconciliation status",
        "description": "Required scope: status:read. Includes public source identity, lastReceivedAt, lastReconciledAt, lastReconcileAttemptAt, reconciliationStatus, reconciliationError, reconciliationChecked, stale and processing counts. Empty successful polls do not mark event delivery verified.",
        "security": [
          {
            "integrationBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid metadata or source",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope, disabled integration or read-only workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in this integration",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflicting mapping, event ID or idempotency key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Payload exceeds 64 KiB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "JSON required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit; honor Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporary storage or verification failure",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/integrations/{organizationId}/{integrationId}/test": {
      "parameters": [
        {
          "name": "organizationId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "integrationId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "testConnection",
        "summary": "Test a generic API connection",
        "description": "Required scope: events:write.",
        "security": [
          {
            "integrationBearer": []
          }
        ],
        "responses": {
          "202": {
            "description": "Accepted durably; query processing status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EventReceipt"
                }
              }
            }
          },
          "400": {
            "description": "Invalid metadata or source",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope, disabled integration or read-only workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in this integration",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflicting mapping, event ID or idempotency key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Payload exceeds 64 KiB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "JSON required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit; honor Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporary storage or verification failure",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Empty"
              }
            }
          }
        }
      }
    },
    "/api/v1/integrations/{organizationId}/{integrationId}/reconcile": {
      "parameters": [
        {
          "name": "organizationId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "integrationId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "recordReconciliation",
        "summary": "Report completion of customer-side metadata reconciliation",
        "description": "Required scope: reconcile:write. Reports a customer-side check; does not fetch provider data or certify rotation. Failed/partial attempts preserve last successful reconciliation.",
        "security": [
          {
            "integrationBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid metadata or source",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope, disabled integration or read-only workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in this integration",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflicting mapping, event ID or idempotency key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Payload exceeds 64 KiB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "JSON required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit; honor Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporary storage or verification failure",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Reconciliation"
              }
            }
          }
        }
      }
    },
    "/api/v1/integrations/{organizationId}/{integrationId}/inventory": {
      "parameters": [
        {
          "name": "organizationId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "integrationId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "listMappedInventory",
        "summary": "List up to 100 mapped records",
        "description": "Required scope: inventory:read.",
        "security": [
          {
            "integrationBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid metadata or source",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope, disabled integration or read-only workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in this integration",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflicting mapping, event ID or idempotency key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Payload exceeds 64 KiB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "JSON required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit; honor Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporary storage or verification failure",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "externalId",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 1000
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      },
      "post": {
        "operationId": "createInventory",
        "summary": "Create inventory and a review-required mapping (generic only)",
        "description": "Required scope: inventory:create.",
        "security": [
          {
            "integrationBearer": []
          }
        ],
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid metadata or source",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope, disabled integration or read-only workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in this integration",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflicting mapping, event ID or idempotency key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Payload exceeds 64 KiB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "JSON required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit; honor Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporary storage or verification failure",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateInventory"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 200
            },
            "description": "Retained for 90 days. Retry with identical fields."
          }
        ]
      }
    },
    "/api/v1/integrations/{organizationId}/{integrationId}/inventory/{id}": {
      "parameters": [
        {
          "name": "organizationId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "integrationId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getMappedInventory",
        "summary": "Get mapped inventory record",
        "description": "Required scope: inventory:read.",
        "security": [
          {
            "integrationBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid metadata or source",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope, disabled integration or read-only workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in this integration",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflicting mapping, event ID or idempotency key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Payload exceeds 64 KiB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "JSON required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit; honor Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporary storage or verification failure",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updateInventory",
        "summary": "Update mapped metadata (generic only); rotations use events",
        "description": "Required scope: inventory:write.",
        "security": [
          {
            "integrationBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid metadata or source",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope, disabled integration or read-only workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in this integration",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflicting mapping, event ID or idempotency key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Payload exceeds 64 KiB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "JSON required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit; honor Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporary storage or verification failure",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InventoryPatch"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 200
            },
            "description": "Retained for 90 days. Retry with identical fields."
          }
        ]
      }
    },
    "/api/v1/integrations/{organizationId}/{integrationId}/mappings": {
      "parameters": [
        {
          "name": "organizationId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "integrationId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "put": {
        "operationId": "saveMapping",
        "summary": "Explicitly link existing workspace inventory and configure allowed updates",
        "description": "Required scope: mappings:write.",
        "security": [
          {
            "integrationBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid metadata or source",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope, disabled integration or read-only workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in this integration",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflicting mapping, event ID or idempotency key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Payload exceeds 64 KiB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "JSON required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit; honor Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporary storage or verification failure",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Mapping"
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "integrationBearer": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "kgr_UUID_RANDOM",
        "description": "One integration only; explicit scopes."
      },
      "eventBridgeKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-KeyGuardRail-Key",
        "description": "EventBridge API Destination API-key connection."
      },
      "providerJWT": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Azure Entra or Google Pub/Sub token, restricted by saved integration identity. Cannot call inventory management endpoints."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        }
      },
      "GenericEvent": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "eventId",
          "externalId",
          "type",
          "occurredAt"
        ],
        "properties": {
          "eventId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "externalId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "type": {
            "type": "string",
            "enum": [
              "created",
              "metadata_changed",
              "metadata_snapshot",
              "rotation_requested",
              "rotation_in_progress",
              "version_created",
              "active_version_changed",
              "rotation_succeeded",
              "rotation_failed",
              "rotation_partial",
              "expiring",
              "expired",
              "deleted",
              "disabled",
              "unavailable",
              "test"
            ]
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time"
          },
          "version": {
            "type": "string",
            "maxLength": 500
          },
          "expiresAt": {
            "type": "string",
            "format": "date"
          }
        }
      },
      "InventoryMetadata": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "provider",
          "credentialType",
          "environment"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 2,
            "maxLength": 120
          },
          "provider": {
            "type": "string",
            "minLength": 2,
            "maxLength": 80
          },
          "credentialType": {
            "type": "string",
            "enum": [
              "api_key",
              "access_key",
              "certificate",
              "pgp_key",
              "oauth_client",
              "service_account",
              "token",
              "other"
            ]
          },
          "environment": {
            "type": "string",
            "enum": [
              "production",
              "staging",
              "development",
              "shared"
            ]
          },
          "ownerName": {
            "type": "string",
            "maxLength": 120
          },
          "expiresAt": {
            "type": "string",
            "format": "date"
          },
          "rotationIntervalDays": {
            "type": "integer",
            "minimum": 1,
            "maximum": 3650
          },
          "runbookUrl": {
            "type": "string",
            "format": "uri",
            "maxLength": 500,
            "pattern": "^https://"
          }
        }
      },
      "Mapping": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "externalId",
          "credentialId"
        ],
        "properties": {
          "externalId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "credentialId": {
            "type": "string",
            "format": "uuid"
          },
          "automatic": {
            "type": "boolean",
            "default": false
          },
          "allowRotation": {
            "type": "boolean",
            "default": true
          },
          "allowExpiration": {
            "type": "boolean",
            "default": false
          },
          "activeVersionIsRotation": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "EventReceipt": {
        "type": "object",
        "properties": {
          "events": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "status": {
                  "type": "string"
                },
                "duplicate": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      },
      "AWS": {
        "type": "object",
        "required": [
          "id",
          "source",
          "account",
          "region",
          "time",
          "detail-type",
          "detail"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "source": {
            "const": "aws.secretsmanager"
          },
          "account": {
            "type": "string",
            "pattern": "^[0-9]{12}$"
          },
          "region": {
            "type": "string"
          },
          "time": {
            "type": "string",
            "format": "date-time"
          },
          "detail-type": {
            "enum": [
              "Secret Label Updated",
              "AWS API Call via CloudTrail",
              "AWS Service Event via CloudTrail"
            ]
          },
          "resources": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "detail": {
            "type": "object"
          }
        }
      },
      "AzureBatch": {
        "type": "array",
        "minItems": 1,
        "maxItems": 20,
        "items": {
          "type": "object",
          "required": [
            "id",
            "topic",
            "eventType",
            "eventTime",
            "data"
          ],
          "properties": {
            "id": {
              "type": "string"
            },
            "topic": {
              "type": "string"
            },
            "eventType": {
              "type": "string"
            },
            "eventTime": {
              "type": "string",
              "format": "date-time"
            },
            "data": {
              "type": "object"
            }
          }
        }
      },
      "GooglePush": {
        "type": "object",
        "required": [
          "subscription",
          "message"
        ],
        "properties": {
          "subscription": {
            "type": "string"
          },
          "message": {
            "type": "object",
            "required": [
              "messageId",
              "attributes"
            ],
            "properties": {
              "messageId": {
                "type": "string"
              },
              "publishTime": {
                "type": "string",
                "format": "date-time"
              },
              "attributes": {
                "type": "object"
              },
              "data": {
                "type": "string",
                "description": "Discarded without decoding."
              }
            }
          }
        }
      },
      "Empty": {
        "type": "object",
        "additionalProperties": false
      },
      "InventoryPatch": {
        "type": "object",
        "additionalProperties": false,
        "required": [],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 2,
            "maxLength": 120
          },
          "provider": {
            "type": "string",
            "minLength": 2,
            "maxLength": 80
          },
          "credentialType": {
            "type": "string",
            "enum": [
              "api_key",
              "access_key",
              "certificate",
              "pgp_key",
              "oauth_client",
              "service_account",
              "token",
              "other"
            ]
          },
          "environment": {
            "type": "string",
            "enum": [
              "production",
              "staging",
              "development",
              "shared"
            ]
          },
          "ownerName": {
            "type": "string",
            "maxLength": 120
          },
          "expiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "rotationIntervalDays": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 3650
          },
          "runbookUrl": {
            "type": "string",
            "format": "uri",
            "maxLength": 500,
            "pattern": "^https://"
          }
        }
      },
      "CreateInventory": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "externalId",
          "metadata"
        ],
        "properties": {
          "externalId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "metadata": {
            "$ref": "#/components/schemas/InventoryMetadata"
          }
        }
      },
      "VaultCollector": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "clusterId",
          "namespace",
          "mount",
          "events"
        ],
        "properties": {
          "clusterId": {
            "type": "string",
            "pattern": "^[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$"
          },
          "namespace": {
            "type": "string"
          },
          "mount": {
            "type": "string"
          },
          "events": {
            "type": "array",
            "minItems": 1,
            "maxItems": 20,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "eventId",
                "path",
                "observedAt",
                "currentVersion",
                "available"
              ],
              "properties": {
                "eventId": {
                  "type": "string",
                  "maxLength": 200
                },
                "path": {
                  "type": "string",
                  "maxLength": 500
                },
                "observedAt": {
                  "type": "string",
                  "format": "date-time"
                },
                "currentVersion": {
                  "type": "integer",
                  "minimum": 1
                },
                "available": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      },
      "OnePasswordCollector": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "accountId",
          "events"
        ],
        "properties": {
          "accountId": {
            "type": "string",
            "pattern": "^[a-zA-Z0-9]{26}$"
          },
          "events": {
            "type": "array",
            "minItems": 1,
            "maxItems": 20,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "uuid",
                "timestamp",
                "action",
                "vault_uuid",
                "item_uuid"
              ],
              "properties": {
                "uuid": {
                  "type": "string",
                  "pattern": "^[a-zA-Z0-9]{26}$"
                },
                "timestamp": {
                  "type": "string",
                  "format": "date-time"
                },
                "action": {
                  "enum": [
                    "server-create",
                    "server-update"
                  ]
                },
                "vault_uuid": {
                  "type": "string",
                  "pattern": "^[a-zA-Z0-9]{26}$"
                },
                "item_uuid": {
                  "type": "string",
                  "pattern": "^[a-zA-Z0-9]{26}$"
                },
                "used_version": {
                  "type": "integer",
                  "minimum": 0
                }
              }
            }
          }
        }
      },
      "BitwardenCollector": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "organizationId",
          "events"
        ],
        "properties": {
          "organizationId": {
            "type": "string",
            "format": "uuid"
          },
          "events": {
            "type": "array",
            "minItems": 1,
            "maxItems": 20,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "type",
                "secretId",
                "date"
              ],
              "properties": {
                "type": {
                  "enum": [
                    2101,
                    2102,
                    2103,
                    2104
                  ]
                },
                "secretId": {
                  "type": "string",
                  "format": "uuid"
                },
                "date": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          }
        }
      },
      "Reconciliation": {
        "type": "object",
        "additionalProperties": false,
        "required": [],
        "properties": {
          "status": {
            "enum": [
              "complete",
              "partial",
              "failed"
            ],
            "default": "complete"
          },
          "checked": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000,
            "default": 0
          },
          "reason": {
            "enum": [
              "source_unavailable",
              "source_unauthorized",
              "rate_limited",
              "delivery_failed",
              "invalid_source_response",
              "checkpoint_invalid",
              "backlog"
            ]
          }
        },
        "description": "Complete must omit reason; partial/failed require reason. Empty object records complete with zero checked. Only complete refreshes lastReconciledAt."
      }
    }
  }
}
