{
  "openapi": "3.0.1",
  "info": {
    "title": "Auto Validation",
    "version": "v1.1"
  },
  "tags": [
    {
      "name": "Auto Validation"
    }
  ],
  "paths": {
    "/auto_validation_documents": {
      "post": {
        "summary": "Submit auto-validation data via CSV",
        "tags": [
          "Auto Validation"
        ],
        "description": "Use this endpoint to submit auto-validation data in bulk via a CSV or XLSX file (50MB at most).\nThe file must include the `MERS MIN` column and every other column marked required in the\neVault's auto-validation template. The file is processed after the response is returned: use\n`GET /auto_validation_entries` to retrieve the resulting entries and their validation results.\n\nExample CSV:\n```            \nMERS MIN,Lender Loan Number,1st Payment Date,Original Loan Amount,Note Rate,P&I,Maturity Date, Street Address,City,State,Zip Code\n999938087932884825,999938087932884825_LoanNumber,04/25/2019,\"330,000.00\",4.000,500.50,04/25/2049,2949 Waterbury Road,Stowe,VT,05662            \n```\n",
        "operationId": "submitAutoValidationCsv",
        "parameters": [],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "201": {
            "description": "created: the file was accepted and is being processed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/auto_validation_document"
                }
              }
            }
          },
          "400": {
            "description": "bad request: no file was provided",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "errors": {
                      "type": "object",
                      "properties": {
                        "file": {
                          "type": "string",
                          "example": "is required"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: authentication is missing or invalid"
          },
          "403": {
            "description": "forbidden: your role does not allow to proceed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/auto_validation_forbidden"
                }
              }
            }
          },
          "422": {
            "description": "unprocessable: the file was rejected",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "File must be a .csv or .xlsx",
                      "description": "Why the file was rejected. One of:\n- `File must be a .csv or .xlsx`\n- `File size is too large (greater than 50MB)`\n- `File is empty`\n- `File is unsafe`: the virus scan failed\n- `File must be in a valid format`: the file could not be parsed\n- `There was an error validating the file headers, please make sure the file is formatted properly`\n- `The following required headers are missing: <headers>`\n- `The following rows have missing or invalid min numbers: <line numbers>`\n"
                    }
                  }
                }
              }
            }
          }
        },
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "The CSV or XLSX file"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/auto_validation_entries": {
      "get": {
        "summary": "Show auto-validation data in aggregate",
        "tags": [
          "Auto Validation"
        ],
        "description": "Use this endpoint to retrieve auto-validation data associated with multiple enotes.\nOnly available to apps, not to users.\n\nResults are ordered by `updated_at`, most recently updated first, unless `sort` is given.\nPages hold 25 entries by default and 200 at most; the `meta` object in the response\ncarries the paging totals.\n\nBy default only the latest entry per MIN is returned. When data is resubmitted for a\nMIN, or an enote is redrawn, a new entry is created and the previous one is retained\nbut no longer considered latest — pass `include_past_data=true` to include those.\n",
        "parameters": [
          {
            "name": "per_page",
            "in": "query",
            "description": "How many results to retrieve per call",
            "schema": {
              "type": "integer",
              "example": 25
            }
          },
          {
            "name": "page",
            "in": "query",
            "description": "Page number of results to retrieve",
            "schema": {
              "type": "integer",
              "example": 1
            }
          },
          {
            "name": "sort",
            "in": "query",
            "description": "Comma-separated list of entry columns to order by, each optionally prefixed with `-` (descending) or `+` (ascending, the default; URL-encode it as `%2B` or leave it out, since a bare `+` decodes to a space). Defaults to `-updated_at`.",
            "schema": {
              "type": "string",
              "example": "-updated_at,min_number"
            }
          },
          {
            "name": "start_date",
            "in": "query",
            "description": "Restricts to entries whose `updated_at` is on or after this value (inclusive). Note that this filters on when the entry was last updated — validation completing or an error being manually resolved both bump `updated_at` — not when the data was first submitted. Accepts a date (`2023-06-01`, interpreted as midnight UTC) or a full ISO 8601 timestamp (`2023-06-01T09:30:00Z`).",
            "schema": {
              "type": "string",
              "example": "2023-06-22T00:00:00.000Z"
            }
          },
          {
            "name": "end_date",
            "in": "query",
            "description": "Restricts to entries whose `updated_at` is on or before this value (inclusive). Filters on `updated_at`, with the same caveats as `start_date`. Accepts a date (`2023-06-01`, interpreted as midnight UTC) or a full ISO 8601 timestamp (`2023-06-01T09:30:00Z`).",
            "schema": {
              "type": "string",
              "example": "2023-06-22T23:59:59.999Z"
            }
          },
          {
            "name": "auto_validated",
            "in": "query",
            "description": "Restricts to entries that either passed (`true`) or failed (`false`) validation. Entries still awaiting a matching enote count as not validated and are returned by `false`. Omit to return entries in both states.",
            "schema": {
              "type": "string",
              "example": "false"
            }
          },
          {
            "name": "include_past_data",
            "in": "query",
            "description": "Set to `true` to also return entries superseded by newer data for the same MIN. Defaults to `false`, which returns only the latest entry per MIN.",
            "schema": {
              "type": "string",
              "example": "true"
            }
          }
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/auto_validation_entries"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: authentication is missing or invalid"
          },
          "403": {
            "description": "forbidden: your role does not allow to proceed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/auto_validation_forbidden"
                }
              }
            }
          }
        }
      }
    },
    "/auto_validation_entries/{min_number}": {
      "get": {
        "summary": "Show auto-validation data for single enote",
        "tags": [
          "Auto Validation"
        ],
        "description": "Use this endpoint to retrieve the latest auto-validation data associated with an enote",
        "operationId": "getAutoValidationEntry",
        "parameters": [
          {
            "name": "min_number",
            "in": "path",
            "required": true,
            "description": "MIN number of the enote to retrieve auto-validation data for, which returns the latest entry for that MIN. The id of a specific entry (as returned by `GET /auto_validation_entries`) is also accepted, and returns that entry.",
            "schema": {
              "type": "string",
              "example": "123456789012345678"
            }
          }
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/auto_validation_entry"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: authentication is missing or invalid"
          },
          "403": {
            "description": "forbidden: your role does not allow to proceed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/auto_validation_forbidden"
                }
              }
            }
          },
          "404": {
            "description": "not found: no entry with this id or MIN in the eVault (the body is `null`)"
          }
        }
      },
      "post": {
        "summary": "Submit auto-validation data",
        "tags": [
          "Auto Validation"
        ],
        "description": "Use this endpoint to submit expected data associated with an enote. Only available to apps,\nnot to users.\n\nThe body is a flat JSON object keyed by the column names of the eVault's auto-validation\nCSV template. A new entry is created and, when the eVault holds an enote with this MIN,\nnormally validated against it before the response is returned. When no enote with this\nMIN has arrived yet, or the validation has to wait on a MERS inquiry, the entry is returned\nunvalidated and validated later; poll `GET /auto_validation_entries/{min_number}` for the\nresult.\n",
        "operationId": "submitAutoValidationEntry",
        "parameters": [
          {
            "name": "min_number",
            "in": "path",
            "required": true,
            "description": "MIN number of the enote to submit auto-validation data for",
            "schema": {
              "type": "string",
              "example": "123456789012345678"
            }
          }
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/auto_validation_entry"
                }
              }
            }
          },
          "400": {
            "description": "bad request: the path parameter contains no digits",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "errors": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "example": [
                        "MIN Number required"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: authentication is missing or invalid"
          },
          "403": {
            "description": "forbidden: your role does not allow to proceed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/auto_validation_forbidden"
                }
              }
            }
          }
        },
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/auto_validation_entry_payload"
              }
            }
          }
        }
      }
    }
  },
  "servers": [
    {
      "url": "https://demo.snapdocsevault.com/api",
      "description": "Snapdocs Evault demo environment"
    },
    {
      "url": "https://www.snapdocsevault.com/api",
      "description": "Snapdocs Evault production environment"
    }
  ],
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "auto_validation_document": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "example": "5279e4ca-cd04-49b3-9863-d94e9acc35fe",
                "description": "The document id"
              },
              "attributes": {
                "type": "object",
                "properties": {
                  "evault_id": {
                    "type": "string",
                    "format": "uuid",
                    "example": "e726f0ee-7c5b-441c-804c-0e91e9ab404a",
                    "description": "id of the evault object"
                  },
                  "file_name": {
                    "type": "string",
                    "example": "auto_validation.csv",
                    "description": "The saved filename"
                  },
                  "processed_row_count": {
                    "type": "integer",
                    "example": 20,
                    "description": "how many rows of data were successfully imported"
                  },
                  "ignored_row_count": {
                    "type": "integer",
                    "example": 3,
                    "description": "how many rows of data were skipped"
                  },
                  "failed_rows": {
                    "type": "object",
                    "description": "details on rows that failed to import. Empty (`{}`) on a successful upload; `missing_min` is only populated when the upload is rejected with a 422 because rows are missing a MIN or have an invalid one",
                    "properties": {
                      "missing_min": {
                        "type": "array",
                        "items": {
                          "type": "integer"
                        },
                        "example": [
                          1,
                          2
                        ],
                        "description": "The CSV line numbers that failed due to a missing or invalid MIN number"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "auto_validation_entry_payload": {
        "type": "object",
        "description": "The expected values for the eNote, keyed by column name. Each key must exactly match one of the `csv_header` values configured for the eVault (the column headers of its auto-validation CSV template); keys that do not match a configured header are dropped. `MERS MIN` is always set from the path parameter and overwrites any value in the body.",
        "additionalProperties": {
          "type": "string"
        },
        "example": {
          "Lender Loan Number": "999938091211784532_LoanNumber",
          "1st Payment Date": "04/25/2019",
          "Original Loan Amount": "330,000.00",
          "Note Rate": "4.000",
          "P&I": "500.50",
          "Maturity Date": "04/25/2049",
          "Street Address": "2949 Waterbury Road",
          "City": "Stowe",
          "State": "VT",
          "Zip Code": "05662"
        }
      },
      "auto_validation_forbidden": {
        "description": "Returned as `{\"error\": \"...\"}` when the token lacks the `auto_validation:basic` scope, or as the bare string `\"Forbidden\"` when auto-validation is not enabled for the eVault or the caller is a user rather than an app",
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "error": {
                "type": "string",
                "example": "Insufficient Scope, a scope of auto_validation:basic is required."
              }
            }
          },
          {
            "type": "string",
            "example": "Forbidden"
          }
        ]
      },
      "pagination_meta": {
        "type": "object",
        "properties": {
          "current_page": {
            "type": "integer",
            "example": 1,
            "description": "The page returned"
          },
          "total_pages": {
            "type": "integer",
            "example": 4,
            "description": "Total number of pages; at least 1"
          },
          "next_page": {
            "type": "integer",
            "nullable": true,
            "example": 2,
            "description": "The next page number, or null when this is the last page"
          },
          "page_size": {
            "type": "integer",
            "example": 25,
            "description": "Number of results per page"
          },
          "total_count": {
            "type": "integer",
            "example": 92,
            "description": "Total number of matching entries"
          }
        }
      },
      "auto_validation_entry_data": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "5279e4ca-cd04-49b3-9863-d94e9acc35fe",
            "description": "The entry id"
          },
          "type": {
            "type": "string",
            "example": "auto_val_entries",
            "description": "The type of object"
          },
          "attributes": {
            "type": "object",
            "properties": {
              "min_number": {
                "type": "string",
                "example": "999938091211784532",
                "description": "MERS min number associated with the relevant enote"
              },
              "auto_validated": {
                "type": "boolean",
                "example": true,
                "description": "tells whether entry has been auto validated"
              },
              "emortgage_package_id": {
                "type": "string",
                "format": "uuid",
                "nullable": true,
                "example": "e726f0ee-7c5b-441c-804c-0e91e9ab404a",
                "description": "id of the emortgage_package (version of the enote) the entry was validated against, null until a matching enote is found"
              },
              "document_id": {
                "type": "string",
                "format": "uuid",
                "nullable": true,
                "example": "e726f0ee-7c5b-441c-804c-0e91e9ab404a",
                "description": "id of the document (enote) the entry was validated against, null until a matching enote is found"
              },
              "updated_at": {
                "type": "string",
                "format": "date-time",
                "example": "2023-06-22T15:04:05.000Z",
                "description": "time the entry was last updated; validation completing or an error being manually resolved both update this"
              },
              "document_errors": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/document_error"
                }
              },
              "document_attribute_errors": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/document_attribute_error"
                }
              }
            }
          }
        }
      },
      "document_attribute_error": {
        "type": "object",
        "description": "an error related to the attributes of the document, if included in auto validation, like an ARM, POA, or Modification error",
        "properties": {
          "id": {
            "type": "string",
            "example": "5279e4ca-cd04-49b3-9863-d94e9acc35fe",
            "description": "The error id"
          },
          "error_key": {
            "type": "string",
            "example": "ARM",
            "description": "an uppercased key identifying the type of attribute error",
            "enum": [
              "ARM",
              "POA",
              "MODIFICATION"
            ]
          },
          "description": {
            "type": "string",
            "example": "eNote is an ARM Note",
            "description": "a description of the attribute error"
          },
          "manually_resolved": {
            "type": "boolean",
            "example": false,
            "description": "whether this error has been manually resolved"
          }
        }
      },
      "document_error": {
        "type": "object",
        "description": "a mismatch between a submitted value and the value found in the enote",
        "properties": {
          "id": {
            "type": "string",
            "example": "5279e4ca-cd04-49b3-9863-d94e9acc35fe",
            "description": "The error id"
          },
          "data": {
            "type": "object",
            "properties": {
              "data": {
                "type": "string",
                "example": "100 Montgomery Street",
                "description": "value provided via the entry data"
              },
              "enote": {
                "type": "string",
                "example": "100 Montgomery St",
                "description": "value parsed from the enote XML"
              }
            }
          },
          "csv_header": {
            "type": "string",
            "example": "Street Address",
            "description": "relevant header in the data file or key in the request body"
          },
          "code": {
            "type": "string",
            "example": "1120",
            "description": "a code for the error type"
          },
          "description": {
            "type": "string",
            "example": "is missing or does not match",
            "description": "a description of the error"
          },
          "exception_type": {
            "type": "string",
            "example": "Non Fatal",
            "enum": [
              "Fatal",
              "Non Fatal"
            ],
            "description": "severity level of auto-validation failure; a `Fatal` error prevents the entry from being auto validated"
          },
          "manually_resolved": {
            "type": "boolean",
            "example": false,
            "description": "whether this error has been manually resolved"
          }
        }
      },
      "auto_validation_entry": {
        "type": "object",
        "properties": {
          "data": {
            "$ref": "#/components/schemas/auto_validation_entry_data"
          }
        }
      },
      "auto_validation_entries": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/auto_validation_entry_data"
            }
          },
          "meta": {
            "$ref": "#/components/schemas/pagination_meta"
          }
        }
      }
    }
  }
}