{
  "openapi": "3.1.0",
  "info": {
    "title": "Fence Partner Integration API",
    "version": "2.0",
    "description": "Machine-readable contract for the Fence API operations documented for integration partners. Access requires credentials provisioned by Fence during onboarding. Deal-specific asset fields are agreed separately and remain explicitly extensible in this contract. The current public API uses the /v2 major-version path. Compatible additive changes may be introduced within a major version; a change that breaks a documented integration requires a new major version. No operation in this description is currently announced for deprecation.",
    "contact": {
      "name": "Fence",
      "url": "https://fence.finance/contact/",
      "email": "hello@fence.finance"
    }
  },
  "externalDocs": {
    "description": "Fence API Client Integration Guide",
    "url": "https://docs.fence.finance/"
  },
  "servers": [
    {
      "url": "https://dev-api.fence.finance",
      "description": "Sandbox API for integration testing. Requires sandbox credentials provisioned by Fence."
    },
    {
      "url": "https://api.fence.finance",
      "description": "Production API. Requires production credentials provisioned by Fence."
    }
  ],
  "tags": [
    {
      "name": "Authentication",
      "description": "Obtain a bearer access token for a machine-to-machine integration."
    },
    {
      "name": "Portfolio declarations",
      "description": "Create and process asset portfolio declarations."
    },
    {
      "name": "Declaration monitoring",
      "description": "Monitor declaration runs and per-asset results."
    },
    {
      "name": "Documents",
      "description": "Register supporting documents and inspect upload status."
    },
    {
      "name": "Payments",
      "description": "Validate or submit payment transactions in bulk."
    }
  ],
  "security": [
    {
      "OAuth2ClientCredentials": []
    }
  ],
  "paths": {
    "/v1/login/access-token": {
      "post": {
        "tags": [
          "Authentication"
        ],
        "operationId": "obtainAccessToken",
        "summary": "Obtain an access token",
        "description": "Exchange a Fence client ID and client secret for a bearer access token using the OAuth 2.0 Client Credentials grant.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/ClientCredentialsTokenRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Access token issued.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccessToken"
                }
              }
            }
          },
          "400": {
            "description": "The request could not be processed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "401": {
            "description": "A valid bearer access token is required.",
            "headers": {
              "WWW-Authenticate": {
                "description": "Bearer authentication challenge.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "422": {
            "description": "The request did not satisfy validation rules.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          }
        }
      }
    },
    "/v2/portfolio_declarations/": {
      "post": {
        "tags": [
          "Portfolio declarations"
        ],
        "operationId": "createPortfolioDeclaration",
        "summary": "Create a portfolio declaration",
        "description": "Create an empty portfolio declaration for a deal before adding assets and triggering processing.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreatePortfolioDeclarationRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Portfolio declaration created.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PortfolioDeclaration"
                }
              }
            }
          },
          "401": {
            "description": "A valid bearer access token is required.",
            "headers": {
              "WWW-Authenticate": {
                "description": "Bearer authentication challenge.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "403": {
            "description": "The client is not authorized for this deal or action.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "404": {
            "description": "The requested deal or resource was not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "422": {
            "description": "The request did not satisfy validation rules.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "500": {
            "description": "An unexpected server error occurred.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          }
        }
      }
    },
    "/v2/portfolio_declarations/{portfolio_declaration_id}/assets": {
      "parameters": [
        {
          "$ref": "#/components/parameters/PortfolioDeclarationId"
        }
      ],
      "post": {
        "tags": [
          "Portfolio declarations"
        ],
        "operationId": "addPortfolioDeclarationAssets",
        "summary": "Add assets to a portfolio declaration",
        "description": "Add a batch of deal-specific assets to an existing portfolio declaration. A request may contain at most 50,000 assets.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "minItems": 1,
                "maxItems": 50000,
                "items": {
                  "$ref": "#/components/schemas/DealSpecificAsset"
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Assets added to the portfolio declaration.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateAssetsResponse"
                }
              }
            }
          },
          "400": {
            "description": "The request could not be processed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "401": {
            "description": "A valid bearer access token is required.",
            "headers": {
              "WWW-Authenticate": {
                "description": "Bearer authentication challenge.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "403": {
            "description": "The client is not authorized for this deal or action.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "404": {
            "description": "The requested deal or resource was not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "409": {
            "description": "The resource state does not allow this operation.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "422": {
            "description": "The request did not satisfy validation rules.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "500": {
            "description": "An unexpected server error occurred.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          }
        }
      }
    },
    "/v2/portfolio_declarations/{portfolio_declaration_id}/declare": {
      "parameters": [
        {
          "$ref": "#/components/parameters/PortfolioDeclarationId"
        }
      ],
      "post": {
        "tags": [
          "Portfolio declarations"
        ],
        "operationId": "declarePortfolioDeclaration",
        "summary": "Trigger a portfolio declaration",
        "description": "Queue an existing portfolio declaration for asynchronous validation and processing.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DeclarePortfolioDeclarationRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Declaration accepted for asynchronous processing.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeclarePortfolioDeclarationResponse"
                }
              }
            },
            "links": {
              "GetDeclarationRun": {
                "operationId": "getDeclarationRun",
                "parameters": {
                  "declaration_id": "$response.body#/id"
                },
                "description": "Poll this operation to monitor the accepted declaration run."
              }
            }
          },
          "401": {
            "description": "A valid bearer access token is required.",
            "headers": {
              "WWW-Authenticate": {
                "description": "Bearer authentication challenge.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "403": {
            "description": "The client is not authorized for this deal or action.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "404": {
            "description": "The requested deal or resource was not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "409": {
            "description": "The resource state does not allow this operation.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "422": {
            "description": "The request did not satisfy validation rules.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "500": {
            "description": "An unexpected server error occurred.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          }
        }
      }
    },
    "/v2/declarations": {
      "get": {
        "tags": [
          "Declaration monitoring"
        ],
        "operationId": "listDeclarationRuns",
        "summary": "List declaration runs",
        "description": "List declaration runs visible to the authenticated client, optionally filtered by deal or portfolio declaration.",
        "parameters": [
          {
            "$ref": "#/components/parameters/OptionalDealId"
          },
          {
            "$ref": "#/components/parameters/OptionalPortfolioDeclarationId"
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated declaration runs.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaginatedDeclarationRuns"
                }
              }
            }
          },
          "401": {
            "description": "A valid bearer access token is required.",
            "headers": {
              "WWW-Authenticate": {
                "description": "Bearer authentication challenge.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "403": {
            "description": "The client is not authorized for this deal or action.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "422": {
            "description": "The request did not satisfy validation rules.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "500": {
            "description": "An unexpected server error occurred.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Portfolio declarations"
        ],
        "operationId": "createFastTrackDeclaration",
        "summary": "Create a fast-track declaration",
        "description": "Create a portfolio declaration, add its deal-specific assets, and queue it for processing in one request.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FastTrackDeclarationRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Declaration accepted for asynchronous processing.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeclarePortfolioDeclarationResponse"
                }
              }
            },
            "links": {
              "GetDeclarationRun": {
                "operationId": "getDeclarationRun",
                "parameters": {
                  "declaration_id": "$response.body#/id"
                },
                "description": "Poll this operation to monitor the accepted declaration run."
              }
            }
          },
          "400": {
            "description": "The request could not be processed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "401": {
            "description": "A valid bearer access token is required.",
            "headers": {
              "WWW-Authenticate": {
                "description": "Bearer authentication challenge.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "403": {
            "description": "The client is not authorized for this deal or action.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "404": {
            "description": "The requested deal or resource was not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "422": {
            "description": "The request did not satisfy validation rules.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "500": {
            "description": "An unexpected server error occurred.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          }
        }
      }
    },
    "/v2/declarations/{declaration_id}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/DeclarationId"
        }
      ],
      "get": {
        "tags": [
          "Declaration monitoring"
        ],
        "operationId": "getDeclarationRun",
        "summary": "Get a declaration run",
        "description": "Retrieve the current state and timestamps for one declaration run.",
        "responses": {
          "200": {
            "description": "Declaration run details.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeclarationRun"
                }
              }
            }
          },
          "401": {
            "description": "A valid bearer access token is required.",
            "headers": {
              "WWW-Authenticate": {
                "description": "Bearer authentication challenge.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "403": {
            "description": "The client is not authorized for this deal or action.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "404": {
            "description": "The requested deal or resource was not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "422": {
            "description": "The request did not satisfy validation rules.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "500": {
            "description": "An unexpected server error occurred.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          }
        }
      }
    },
    "/v2/declarations/{declaration_id}/assets": {
      "parameters": [
        {
          "$ref": "#/components/parameters/DeclarationId"
        }
      ],
      "get": {
        "tags": [
          "Declaration monitoring"
        ],
        "operationId": "listDeclarationRunAssets",
        "summary": "List declaration asset results",
        "description": "List per-asset processing results for a declaration run with optional eligibility filters.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "external_asset_ids",
            "in": "query",
            "required": false,
            "description": "External asset identifiers to include.",
            "style": "form",
            "explode": true,
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "is_eligible",
            "in": "query",
            "required": false,
            "description": "Filter by the final eligibility result.",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "is_declarable",
            "in": "query",
            "required": false,
            "description": "Filter by the final declarability result.",
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated declaration asset results.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaginatedDeclarationRunAssets"
                }
              }
            }
          },
          "401": {
            "description": "A valid bearer access token is required.",
            "headers": {
              "WWW-Authenticate": {
                "description": "Bearer authentication challenge.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "403": {
            "description": "The client is not authorized for this deal or action.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "404": {
            "description": "The requested deal or resource was not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "422": {
            "description": "The request did not satisfy validation rules.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "500": {
            "description": "An unexpected server error occurred.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          }
        }
      }
    },
    "/v2/declarations/{declaration_id}/assets/{portfolio_declaration_asset_id}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/DeclarationId"
        },
        {
          "$ref": "#/components/parameters/PortfolioDeclarationAssetId"
        }
      ],
      "get": {
        "tags": [
          "Declaration monitoring"
        ],
        "operationId": "getDeclarationRunAsset",
        "summary": "Get one declaration asset result",
        "description": "Retrieve all processing-step results for one asset in a declaration run.",
        "responses": {
          "200": {
            "description": "Declaration asset processing results.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeclarationRunAsset"
                }
              }
            }
          },
          "401": {
            "description": "A valid bearer access token is required.",
            "headers": {
              "WWW-Authenticate": {
                "description": "Bearer authentication challenge.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "403": {
            "description": "The client is not authorized for this deal or action.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "404": {
            "description": "The requested deal or resource was not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "422": {
            "description": "The request did not satisfy validation rules.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "500": {
            "description": "An unexpected server error occurred.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          }
        }
      }
    },
    "/v2/{deal_id}/documents": {
      "parameters": [
        {
          "$ref": "#/components/parameters/DealId"
        }
      ],
      "get": {
        "tags": [
          "Documents"
        ],
        "operationId": "getDocumentUploadStatuses",
        "summary": "Get document upload statuses",
        "description": "Retrieve upload status and, for pending uploads, a fresh presigned URL for selected documents.",
        "parameters": [
          {
            "name": "document_external_ids",
            "in": "query",
            "required": true,
            "description": "Comma-separated external document identifiers.",
            "schema": {
              "type": "string",
              "minLength": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Matching document upload statuses.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentsResponse"
                }
              }
            }
          },
          "401": {
            "description": "A valid bearer access token is required.",
            "headers": {
              "WWW-Authenticate": {
                "description": "Bearer authentication challenge.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "403": {
            "description": "The client is not authorized for this deal or action.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "404": {
            "description": "The requested deal or resource was not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "422": {
            "description": "The request did not satisfy validation rules.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "500": {
            "description": "An unexpected server error occurred.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Documents"
        ],
        "operationId": "registerDocuments",
        "summary": "Register documents for upload",
        "description": "Register one or more supporting documents and receive presigned URLs for uploading their files.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RegisterDocumentsRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Documents registered for upload.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentsResponse"
                }
              }
            }
          },
          "401": {
            "description": "A valid bearer access token is required.",
            "headers": {
              "WWW-Authenticate": {
                "description": "Bearer authentication challenge.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "403": {
            "description": "The client is not authorized for this deal or action.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "404": {
            "description": "The requested deal or resource was not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "422": {
            "description": "The request did not satisfy validation rules.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "500": {
            "description": "An unexpected server error occurred.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          }
        }
      }
    },
    "/v2/{deal_id}/payments/bulk": {
      "parameters": [
        {
          "$ref": "#/components/parameters/DealId"
        }
      ],
      "post": {
        "tags": [
          "Payments"
        ],
        "operationId": "bulkCreatePayments",
        "summary": "Validate or submit payment transactions",
        "description": "Validate payment transactions synchronously when dry_run is true, or enqueue them for asynchronous creation when dry_run is false.",
        "parameters": [
          {
            "name": "dry_run",
            "in": "query",
            "required": false,
            "description": "When true, validate without creating transactions. Set false explicitly to enqueue live processing.",
            "schema": {
              "type": "boolean",
              "default": true
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BulkPaymentsRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Synchronous validation result, including per-transaction failures.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BulkOperationResult"
                }
              }
            }
          },
          "202": {
            "description": "Transactions accepted for asynchronous processing.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AsyncPaymentsAccepted"
                }
              }
            }
          },
          "400": {
            "description": "The request could not be processed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "401": {
            "description": "A valid bearer access token is required.",
            "headers": {
              "WWW-Authenticate": {
                "description": "Bearer authentication challenge.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "403": {
            "description": "The client is not authorized for this deal or action.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "404": {
            "description": "The requested deal or resource was not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "422": {
            "description": "The request did not satisfy validation rules.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          },
          "500": {
            "description": "An unexpected server error occurred.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "OAuth2ClientCredentials": {
        "type": "oauth2",
        "description": "OAuth 2.0 Client Credentials grant for server-to-server integrations. Fence provisions credentials separately for each environment.",
        "flows": {
          "clientCredentials": {
            "tokenUrl": "/v1/login/access-token",
            "scopes": {}
          }
        }
      }
    },
    "parameters": {
      "DealId": {
        "name": "deal_id",
        "in": "path",
        "required": true,
        "description": "Fence deal identifier provisioned for the target environment.",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "OptionalDealId": {
        "name": "deal_id",
        "in": "query",
        "required": false,
        "description": "Return declaration runs for one accessible deal.",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "PortfolioDeclarationId": {
        "name": "portfolio_declaration_id",
        "in": "path",
        "required": true,
        "description": "Portfolio declaration identifier.",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "OptionalPortfolioDeclarationId": {
        "name": "portfolio_declaration_id",
        "in": "query",
        "required": false,
        "description": "Return runs for one portfolio declaration.",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "DeclarationId": {
        "name": "declaration_id",
        "in": "path",
        "required": true,
        "description": "Declaration run identifier returned by a declare operation.",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "PortfolioDeclarationAssetId": {
        "name": "portfolio_declaration_asset_id",
        "in": "path",
        "required": true,
        "description": "Asset identifier within a portfolio declaration.",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "Page": {
        "name": "page",
        "in": "query",
        "required": false,
        "description": "One-indexed result page.",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "default": 1
        }
      },
      "PageSize": {
        "name": "page_size",
        "in": "query",
        "required": false,
        "description": "Number of results per page.",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000,
          "default": 100
        }
      }
    },
    "schemas": {
      "ClientCredentialsTokenRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "grant_type",
          "client_id",
          "client_secret"
        ],
        "properties": {
          "grant_type": {
            "type": "string",
            "const": "client_credentials"
          },
          "client_id": {
            "type": "string",
            "minLength": 1
          },
          "client_secret": {
            "type": "string",
            "format": "password",
            "minLength": 1
          }
        }
      },
      "AccessToken": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "access_token",
          "token_type",
          "expires_in"
        ],
        "properties": {
          "access_token": {
            "type": "string",
            "minLength": 1
          },
          "token_type": {
            "type": "string",
            "description": "Bearer token type."
          },
          "expires_in": {
            "type": "integer",
            "minimum": 1,
            "description": "Lifetime of the access token in seconds."
          }
        }
      },
      "CreatePortfolioDeclarationRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "deal_id"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1
          },
          "deal_id": {
            "type": "string",
            "format": "uuid"
          }
        }
      },
      "PortfolioDeclaration": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "deal_id",
          "name",
          "asset_count",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "deal_id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "asset_count": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "DealSpecificAsset": {
        "type": "object",
        "minProperties": 1,
        "description": "Asset payload validated against the schema configured for the target deal. Common integrations use external_id, contract_external_id, and properties; Fence provides the authoritative deal-specific fields during onboarding.",
        "properties": {
          "external_id": {
            "type": "string",
            "minLength": 1,
            "description": "Client-controlled asset identifier when required by the deal schema."
          },
          "contract_external_id": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1
          },
          "properties": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/DealSpecificProperties"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "additionalProperties": true
      },
      "DealSpecificProperties": {
        "type": "object",
        "description": "Fields vary by deal and are defined in the integration-specific schema provided during onboarding.",
        "additionalProperties": true
      },
      "CreatedAsset": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "external_id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "external_id": {
            "type": "string"
          }
        }
      },
      "CreateAssetsResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "data"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CreatedAsset"
            }
          }
        }
      },
      "DeclarePortfolioDeclarationRequest": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "dry_run": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "FastTrackDeclarationRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "deal_id",
          "assets"
        ],
        "properties": {
          "deal_id": {
            "type": "string",
            "format": "uuid"
          },
          "dry_run": {
            "type": "boolean",
            "default": false
          },
          "assets": {
            "type": "array",
            "minItems": 1,
            "maxItems": 50000,
            "items": {
              "$ref": "#/components/schemas/DealSpecificAsset"
            }
          }
        }
      },
      "DeclarationRunStatus": {
        "type": "string",
        "enum": [
          "queued",
          "processing",
          "completed",
          "completed_with_errors",
          "failed"
        ]
      },
      "DeclarePortfolioDeclarationResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "status",
          "dry_run"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "$ref": "#/components/schemas/DeclarationRunStatus"
          },
          "dry_run": {
            "type": "boolean"
          }
        }
      },
      "DeclarationRun": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "portfolio_declaration_id",
          "dry_run",
          "status"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "portfolio_declaration_id": {
            "type": "string",
            "format": "uuid"
          },
          "dry_run": {
            "type": "boolean"
          },
          "status": {
            "$ref": "#/components/schemas/DeclarationRunStatus"
          },
          "started_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "completed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "PaginatedDeclarationRuns": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "data",
          "total",
          "page",
          "size",
          "pages"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DeclarationRun"
            }
          },
          "total": {
            "type": "integer",
            "minimum": 0
          },
          "page": {
            "type": "integer",
            "minimum": 1
          },
          "size": {
            "type": "integer",
            "minimum": 1
          },
          "pages": {
            "type": "integer",
            "minimum": 0
          }
        }
      },
      "DeclarationAssetResultStatus": {
        "type": "string",
        "enum": [
          "successful",
          "unsuccessful",
          "failed"
        ]
      },
      "DeclarationAssetStepResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "step_name",
          "status",
          "details"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "step_name": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/DeclarationAssetResultStatus"
          },
          "details": {
            "oneOf": [
              {
                "type": "object",
                "additionalProperties": true
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "DeclarationRunAsset": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "asset_id",
          "external_asset_id",
          "contract_external_id",
          "properties",
          "results"
        ],
        "properties": {
          "asset_id": {
            "type": "string",
            "format": "uuid"
          },
          "external_asset_id": {
            "type": "string"
          },
          "contract_external_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "properties": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/DealSpecificProperties"
              },
              {
                "type": "null"
              }
            ]
          },
          "is_eligible": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "is_declarable": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "results": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DeclarationAssetStepResult"
            }
          }
        }
      },
      "PaginatedDeclarationRunAssets": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "data",
          "total",
          "page",
          "size",
          "pages"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DeclarationRunAsset"
            }
          },
          "total": {
            "type": "integer",
            "minimum": 0
          },
          "page": {
            "type": "integer",
            "minimum": 1
          },
          "size": {
            "type": "integer",
            "minimum": 1
          },
          "pages": {
            "type": "integer",
            "minimum": 0
          }
        }
      },
      "DocumentInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "document_category",
          "document_external_id",
          "file_name_with_ext"
        ],
        "properties": {
          "document_category": {
            "type": "string",
            "minLength": 1
          },
          "document_external_id": {
            "type": "string",
            "minLength": 1
          },
          "file_name_with_ext": {
            "type": "string",
            "pattern": "^.+\\.[^./]+$",
            "description": "File name including its extension."
          },
          "title": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "RegisterDocumentsRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "documents"
        ],
        "properties": {
          "documents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentInput"
            }
          }
        }
      },
      "Document": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "document_external_id"
        ],
        "properties": {
          "document_external_id": {
            "type": "string"
          },
          "presigned_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          },
          "expires_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "uploaded_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "DocumentsResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "documents"
        ],
        "properties": {
          "documents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Document"
            }
          }
        }
      },
      "PaymentTransactionType": {
        "type": "string",
        "enum": [
          "expense",
          "borrow",
          "repayment",
          "waterfall_payment",
          "intake",
          "intake_meta",
          "outbound",
          "outgoing_type",
          "disposition",
          "utilization"
        ]
      },
      "PaymentMetadata": {
        "type": "object",
        "required": [
          "metadata_type"
        ],
        "properties": {
          "metadata_type": {
            "type": "string",
            "enum": [
              "intake",
              "intake_meta",
              "expense",
              "borrow",
              "repayment",
              "utilization",
              "outgoing_type"
            ]
          },
          "deal_specific_metadata": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "PaymentTransaction": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "external_id",
          "amount",
          "transaction_date"
        ],
        "properties": {
          "external_id": {
            "type": "string",
            "minLength": 1
          },
          "from_": {
            "type": [
              "string",
              "null"
            ]
          },
          "to_": {
            "type": [
              "string",
              "null"
            ]
          },
          "amount": {
            "type": "number"
          },
          "memo": {
            "type": [
              "string",
              "null"
            ]
          },
          "iban": {
            "type": [
              "string",
              "null"
            ]
          },
          "routing_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "account_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "transaction_date": {
            "type": "string",
            "format": "date-time"
          },
          "bank_account_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "currency": {
            "type": "string",
            "enum": [
              "ALL",
              "ARS",
              "AUD",
              "BGN",
              "BOB",
              "BRL",
              "BZD",
              "CAD",
              "CHF",
              "CLP",
              "CNY",
              "COP",
              "CRC",
              "CZK",
              "DKK",
              "EGP",
              "EUR",
              "GBP",
              "GEL",
              "GTQ",
              "HKD",
              "HUF",
              "IDR",
              "ILS",
              "INR",
              "ISK",
              "JPY",
              "KHR",
              "KRW",
              "LAK",
              "LKR",
              "MAD",
              "MKD",
              "MVR",
              "MXN",
              "MYR",
              "NOK",
              "NZD",
              "PAB",
              "PEN",
              "PHP",
              "PLN",
              "PYG",
              "RON",
              "RSD",
              "SEK",
              "SGD",
              "THB",
              "TRY",
              "TZS",
              "USD",
              "UYU",
              "VND",
              "ZAR"
            ],
            "default": "EUR"
          },
          "intake_source": {
            "type": [
              "string",
              "null"
            ],
            "default": "banking"
          },
          "transaction_type": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/PaymentTransactionType"
              },
              {
                "type": "null"
              }
            ]
          },
          "metadata": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/PaymentMetadata"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "BulkPaymentsRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "data"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PaymentTransaction"
            }
          }
        }
      },
      "BulkOperationResult": {
        "type": "object",
        "additionalProperties": true,
        "required": [
          "entity_name"
        ],
        "properties": {
          "declaration_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "entity_name": {
            "type": "string"
          },
          "failed": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "message": {
            "type": [
              "string",
              "null"
            ]
          },
          "source": {
            "type": [
              "string",
              "null"
            ]
          },
          "successful": {
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "object",
                  "additionalProperties": true
                }
              ]
            }
          },
          "valid": {
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "object",
                  "additionalProperties": true
                }
              ]
            }
          },
          "delta_borrow_base": {
            "type": [
              "number",
              "null"
            ]
          }
        }
      },
      "AsyncPaymentsAccepted": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "declaration_id",
          "accepted",
          "accepted_count",
          "failed_count",
          "failed",
          "message"
        ],
        "properties": {
          "declaration_id": {
            "type": "string",
            "format": "uuid"
          },
          "accepted": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "accepted_count": {
            "type": "integer",
            "minimum": 0
          },
          "failed_count": {
            "type": "integer",
            "minimum": 0
          },
          "failed": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "message": {
            "type": "string"
          }
        }
      },
      "ValidationIssue": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "loc": {
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "integer"
                }
              ]
            }
          },
          "msg": {
            "type": "string"
          },
          "type": {
            "type": "string"
          }
        }
      },
      "HttpError": {
        "type": "object",
        "additionalProperties": true,
        "required": [
          "detail"
        ],
        "properties": {
          "detail": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/ValidationIssue"
                }
              },
              {
                "type": "object",
                "additionalProperties": true
              }
            ]
          }
        }
      }
    }
  }
}
