> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lendflow.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Middesk Bankruptcies

## Middesk Bankruptcies

The **Middesk Bankruptcies** Workflow Builder block checks a business for bankruptcy cases. The block runs the shared `middesk` service and reads the `bankruptcies` portion of the stored Middesk business response.

## What the service returns

| Result area | Meaning |
| - | - |
| Bankruptcy cases | Cases associated with the business, including case, court, debtor, filing, and update data when Middesk returns it. |
| Review task | A `review.tasks` item with `key: "bankruptcies"` is Middesk's review outcome, not a case. |
| Lifecycle and request | Lendflow stores the latest status, service date, and sanitized request separately from the provider result. |

An empty `bankruptcies` array means Middesk returned no cases in the stored response. Check the lifecycle status separately to confirm that the run succeeded.

## Requirements

| Application field | Requirement | Notes |
| - | - | - |
| Business legal name | Required | Use the legal name stored on the application. |
| Primary business address line 1, city, state, and ZIP code | Required | Provide all listed address fields. |
| Primary owner's telephone | Required | Use a valid United States telephone number. |
| Every owner's full name | Required | Provide the full name for each owner on the application. |
| Owner date of birth | Optional | Use `YYYY/MM/DD` when provided. |
| EIN | Optional | The value must pass validation when provided. |
| Website, DBA, and formation state | Optional | These fields provide additional business information when available. |

## Run the service

Call [Enrich Business Credit Application](/api-reference/workflow-management/enrich-business-credit-application) at `PUT /api/applications/{application_id}/enrich`:

```json theme={"system"}
{
  "provider": "middesk"
}
```

Do not send `options` for the bankruptcy block. Middesk product options control lien orders.

The response `{"data":{"onqueue":true}}` confirms only that Lendflow queued the job.

## Retrieve the result

Poll [Get Commercial Data](/api-reference/workflow-management/get-commercial-data) with `services[]=middesk`.

| Data | Response path |
| - | - |
| Stored Middesk response | `commercial_data.middesk` |
| Bankruptcy cases | `commercial_data.middesk.bankruptcies` |
| Review tasks | `commercial_data.middesk.review.tasks` |
| Latest status | `statuses.middesk` |
| Stored request | `request_data.middesk` |
| Latest date | `dates.middesk` |

Call `GET /api/applications/{application_id}/commercial_data?services[]=middesk`. Use `statuses.middesk` and `dates.middesk` to track the latest run, `commercial_data.middesk` for the provider response, and `request_data.middesk` for the stored request.

## Asynchronous behavior

Middesk is always queued. Lendflow creates the business, waits for Middesk webhooks, and refreshes the stored response. The run becomes `Success` only after the Middesk business status is `in_review`, `approved`, or `declined` and every returned order is `completed`.

Rerunning creates another `middesk` run. Evaluate the latest lifecycle record and stored response.

## Example response

```json theme={"system"}
{
  "bankruptcies": [
    {
      "id": "bankruptcy_example_001",
      "object": "bankruptcy",
      "chapter": 11,
      "court": "Northern District of Illinois",
      "case_number": "1:21-bk-01231",
      "filing_date": "2021-03-26",
      "debtors": [{ "name": "Example Company LLC" }],
      "case_updates": [
        {
          "description": "Final Decree",
          "guid": "https://example.com/cases/1",
          "pub_date": "2022-01-26 22:54:05.000000 UTC"
        }
      ]
    }
  ]
}
```

## Response fields

| Field | Type | Meaning | Values or format | When returned |
| - | - | - | - | - |
| `bankruptcies` | array | Cases associated with the business. | Empty or case objects. | When bankruptcy data is included. |
| `bankruptcies[].id` | string | Middesk case-object identifier. | Provider identifier. | For each case. |
| `bankruptcies[].object` | string | Middesk object type. | `bankruptcy`. | For each case. |
| `bankruptcies[].chapter` | integer or string | Bankruptcy code chapter. | Provider value such as `7`, `11`, or `13`. | When available. |
| `bankruptcies[].court` | string | Court associated with the case. | Court name. | When available. |
| `bankruptcies[].case_number` | string | Court case number. | Court-defined format. | When available. |
| `bankruptcies[].filing_date` | string | Filing date. | `YYYY-MM-DD`. | When available. |
| `bankruptcies[].debtors` | array | Debtors named on the case. | Debtor objects. | For a returned case. |
| `bankruptcies[].debtors[].name` | string | Reported debtor name. | Business or person name. | For each debtor. |
| `bankruptcies[].case_updates` | array | Published case updates. | Empty or update objects. | When updates exist. |
| `bankruptcies[].case_updates[].description` | string | Update summary. | Provider text. | For each update. |
| `bankruptcies[].case_updates[].guid` | string | Source URL or identifier. | URL when supplied. | For each update. |
| `bankruptcies[].case_updates[].pub_date` | string | Publication timestamp. | Provider timestamp, commonly UTC. | For each update. |

The provider can omit unavailable fields or return additional fields. The example is intentionally representative, not a complete Middesk schema.

## Data Orchestration

Middesk Bankruptcies is available under **Bankruptcies → Middesk**. Conditions use the completed `middesk` result, so the service must run before dependent conditions are evaluated.

## Errors

| Result | Meaning | Action |
| - | - | - |
| HTTP `401` or `403` | Authentication or application permission failed. | Use a token with view and enrichment access. |
| HTTP `422` | The provider is unavailable to the client or the body is invalid. | Confirm `middesk` access and omit unsupported options. |
| Status contains `field contains an invalid number` | The owner phone failed Middesk validation. | Correct the phone and rerun. |
| `failed_at` or an error status | Validation, provider, or webhook processing failed. | Read the lifecycle `error` or `statuses.middesk`, correct the cause, and rerun. |
| Run remains in progress | Middesk has not reached a complete business-and-orders state. | Continue polling. |

## FAQ

<AccordionGroup>
  <Accordion title="Does this block have a separate bankruptcy service ID?">
    No. The block ID is `middesk_bankruptcies`, but it runs `middesk` and reads `commercial_data.middesk.bankruptcies`.
  </Accordion>

  <Accordion title="Should I send lien options?">
    No. Lien options belong to the Middesk Liens block.
  </Accordion>

  <Accordion title="Does onqueue true mean the check finished?">
    No. It means the job was queued. Poll until `statuses.middesk` reaches `Success` or contains an error.
  </Accordion>

  <Accordion title="What does an empty bankruptcies array mean?">
    It means no cases were returned in the stored response. Confirm `Success` separately.
  </Accordion>
</AccordionGroup>
