> ## 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.

# Data Orchestration via API

## Data Orchestration via API

Use the Lendflow API to run a published Data Orchestration template on a deal, monitor the run, inspect its decision history, and act on the result. A deal is represented by an application in the API.

Before you begin, obtain a Bearer token, the application ID for the deal, and access to a published Data Orchestration template that is compatible with the application.

## API flow

1. **Find a published template.** Call [List Data Orchestration Templates](/api-reference/data-orchestration/list-data-orchestration-templates) with the application ID and `stage_id`. Save the template `id`; you will send it as `template_id` when starting the run.
2. **Start Data Orchestration.** Call [Execute Data Orchestration](/api-reference/data-orchestration/execute-data-orchestration) for the application with `template_id`, `application_id`, and the applicable `stage_id`.
3. **Confirm the request was accepted.** A successful request returns `200 OK` with `data.executed` set to `true`. The response does not return `template_id`. Execution is scheduled asynchronously, so this response does not mean that processing has finished.
4. **Monitor the run.** Use [List Data Orchestration Logs](/api-reference/data-orchestration/list-data-orchestration-logs) to list recent runs and obtain the log ID. Then use [Get Data Orchestration Log](/api-reference/data-orchestration/get-data-orchestration-log) with the application ID and log ID to retrieve one run. The log resource includes the overall `outcome`, `master_status`, timestamps, errors, and status history. Refer to these API Reference endpoints for the complete current response schema.
5. **Inspect decision details.** Use `history` to review each evaluated step. When you need to identify the condition that produced a pass, fail, or review result, inspect the step's `context.log`, including its attribute, conditions, value, outcome, and boolean evaluation results.
6. **Act on the outcome.** Your integration can map the overall result or individual step outcomes to its next action. For example, after your organization has configured its document requirements and supplied their IDs, use [Update Application Stips](/api-reference/workflow-management/update-application-stips) to set required documents on the application. Keep this mapping in your integration so that the documents added to a deal match your organization's policy.

Example execute response:

```json theme={"system"}
{
  "data": {
    "executed": true
  }
}
```

## Continue or override an existing run

The execute operation starts a new run. The following operations use the `log_id` of an existing run and do not create a separate run:

| Job | API operation | Behavior |
| - | - | - |
| Retry the last step | [Retry Last Data Orchestration Step](/api-reference/data-orchestration/retry-last-data-orchestration-step) | Re-runs the most recent step and queues the existing run to continue asynchronously. |
| Resume with a pass | [Continue Data Orchestration as Pass](/api-reference/data-orchestration/continue-data-orchestration-as-pass) | Marks the current step as passed and queues the existing run to continue. |
| Resume with a fail | [Continue Data Orchestration as Fail](/api-reference/data-orchestration/continue-data-orchestration-as-fail) | Marks the current step as failed and queues the existing run to continue. |
| Override the overall status | [Update Data Orchestration Master Status](/api-reference/data-orchestration/update-data-orchestration-master-status) | Sets `master_status` on the existing run and can record a comment in its history. |

The retry and pass/fail continuation operations return `202 Accepted` with an empty JSON object. Updating the master status returns `200 OK` with the updated log under `data`.

## Master status values

Use `master_status` to determine whether the run is still active or has reached a terminal result.

| Value | Status |
| - | - |
| `0` | Not Started |
| `2` | Processing |
| `3` | Review |
| `4` | Complete Pass |
| `5` | Complete Fail |
| `6` | Error |

The top-level `master_status` describes the overall run. The outcomes inside `history` explain how individual steps contributed to that result.

## Webhook notifications

If your integration should receive notifications instead of polling the logs endpoints, configure the applicable Data Orchestration events in [Custom Workflow Webhooks](/lendflow-external/docs/custom-workflows-webhooks).

## FAQ

<AccordionGroup>
  <Accordion title="Does starting Data Orchestration return an empty response?">
    No. A successful request returns `200 OK` with `data.executed` set to `true`. It does not return `template_id`. Use List Data Orchestration Logs to find the scheduled run and monitor its status.
  </Accordion>

  <Accordion title="How do I know when a run has finished?">
    Retrieve the log and check `master_status`. Values `4`, `5`, and `6` represent Complete Pass, Complete Fail, and Error. Values `0`, `2`, and `3` represent Not Started, Processing, and Review.
  </Accordion>

  <Accordion title="Where can I see which rule caused the result?">
    Retrieve the individual log and inspect its `history`. Each step can include `context.log` entries showing the evaluated attribute, value, conditions, outcome, and evaluation results.
  </Accordion>

  <Accordion title="Can I require documents based on the result?">
    Yes. Map the overall result or relevant step outcomes to your organization's document IDs, then call the Update Application Stips endpoint for the application.
  </Accordion>

  <Accordion title="Should I poll the log or use a webhook?">
    Use log polling when your integration controls the check interval. Use Custom Workflow Webhooks when your integration should receive event notifications at a configured URL.
  </Accordion>

  <Accordion title="Does retrying start a new Data Orchestration run?">
    No. Execute Data Orchestration starts a new run. Retry Last Data Orchestration Step and the pass/fail continuation operations act on an existing run identified by `log_id`.
  </Accordion>
</AccordionGroup>

## Next steps

<Card title="Configure Custom Workflow Webhooks" icon="webhook" href="/lendflow-external/docs/custom-workflows-webhooks" horizontal>
  Send workflow and Data Orchestration notifications to your integration.
</Card>
