{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.firstmilelabs.com/schemas/webhooks/document_request.created.v1.json",
  "title": "FirstMileLabs Outbound Webhook — document_request.created (v1)",
  "description": "A case's customer was asked for what they still owe: by the app's composer, the automatic triggers, or POST /v1/cases/{caseId}/document-requests. A request to someone a request is still open to joins it (joined: true): one link for everything. Ids, counts and what each item asks for: never the upload link, a person's name or the customer's words.",
  "type": "object",
  "additionalProperties": true,
  "required": [
    "event",
    "eventId",
    "eventVersion",
    "timestamp",
    "orgId",
    "caseId",
    "requestId",
    "delivery",
    "source",
    "joined",
    "addedCount",
    "itemCount",
    "expiresAt",
    "items"
  ],
  "properties": {
    "event": {
      "type": "string",
      "const": "document_request.created"
    },
    "eventId": {
      "type": "string",
      "format": "uuid"
    },
    "eventVersion": {
      "type": "integer",
      "const": 1
    },
    "timestamp": {
      "type": "string",
      "format": "date-time"
    },
    "orgId": {
      "type": "string"
    },
    "crmRecordId": {
      "type": [
        "string",
        "null"
      ],
      "description": "Your own reference for the case, when it has one."
    },
    "crmSource": {
      "type": [
        "string",
        "null"
      ]
    },
    "caseId": {
      "type": "string",
      "description": "The customer's case."
    },
    "requestId": {
      "type": "integer",
      "description": "The request. Stable across its events, and what POST /v1/cases/{caseId}/document-requests returns."
    },
    "delivery": {
      "type": "string",
      "enum": [
        "email",
        "link"
      ],
      "description": "email: we emailed the customer. link: the link went back to whoever asked through the API, to send themselves."
    },
    "source": {
      "type": "string",
      "enum": [
        "app",
        "api",
        "automatic"
      ],
      "description": "Who asked: someone in the app, your API key, or the platform (a trigger, or an expired link sent again)."
    },
    "joined": {
      "type": "boolean",
      "description": "The items joined a request already open to the same person."
    },
    "addedCount": {
      "type": "integer",
      "minimum": 0,
      "description": "How many items were new to the request."
    },
    "itemCount": {
      "type": "integer",
      "minimum": 0,
      "description": "Everything on the request still owed."
    },
    "expiresAt": {
      "type": "string",
      "format": "date-time",
      "description": "When its link stops working."
    },
    "items": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true,
        "required": [
          "index",
          "category",
          "docType",
          "eddReqKey",
          "personRef",
          "status",
          "documentIds"
        ],
        "properties": {
          "index": {
            "type": "integer",
            "minimum": 0,
            "description": "Its position on the request. GET /v1/cases/{caseId}/document-requests has the rest of it."
          },
          "category": {
            "type": [
              "string",
              "null"
            ]
          },
          "docType": {
            "type": [
              "string",
              "null"
            ],
            "description": "A document's requirement: a classifier type, or your own key."
          },
          "eddReqKey": {
            "type": [
              "string",
              "null"
            ],
            "description": "The EDD requirement it answers; sow_person for a person's Source of Wealth."
          },
          "personRef": {
            "type": [
              "string",
              "null"
            ],
            "description": "The person a Source of Wealth is for."
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "uploaded",
              "declared",
              "cannot_provide",
              "not_applicable"
            ]
          },
          "documentIds": {
            "type": "array",
            "items": {
              "type": [
                "integer",
                "string"
              ]
            },
            "description": "The documents the customer sent for it."
          }
        }
      },
      "description": "Everything on the request still owed."
    }
  }
}
