---
title: Generate and distribute a document through the Document API
summary: Build a one-distribution Document API request and post it to `/v1/distribute`.
status: draft
owner: Technical Writer
last_reviewed: 2026-07-31
library: SAIF.Business.Policy.Audit.ApiCalls
reference_type: package
operation_id: OP-005
trigger: A caller invokes `CallDocumentApi(packageName, documentXml, options)`.
---

# Generate and distribute a document through the Document API

Build a one-distribution Document API request and post it to `/v1/distribute`.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-005 |
| **Trigger** | A caller invokes `CallDocumentApi(packageName, documentXml, options)`. |
| **Inputs** | `string packageName`, `string documentXml`, `DistributionOptions options`. |
| **Outputs** | `bool` success flag. |
| **Primary components** | `DocumentApiCall.CallDocumentApi` |
| **Entry point** | `Business\SAIF.Business.Policy.Audit.ApiCalls\DocumentApiCall.cs` |

## Steps

1. Create `DistributionRequest` and stamp `Username` with `PremAudit` ([BR-AAC-010](../business-rules.md#br-aac-010-document-api-requests-use-submitter-name-premaudit)).
2. Populate `BaseDocumentXML` from the caller input and allocate a single-element `Distributions` array ([BR-AAC-011](../business-rules.md#br-aac-011-document-api-requests-carry-exactly-one-distribution-entry)).
3. Inside that one `DistributionConfig`, leave `DistributionGroup` and `RecipientName` empty and set `DistributionTime` to `null` for immediate distribution ([BR-AAC-012](../business-rules.md#br-aac-012-null-distribution-time-means-immediate-distribution)).
4. Create `DocumentConfig` with the caller's package name, `OutputProfile = PDF`, and `RecipientId = PH` ([BR-AAC-013](../business-rules.md#br-aac-013-document-api-output-profile-is-pdf), [BR-AAC-014](../business-rules.md#br-aac-014-document-api-recipient-is-the-policy-holder)).
5. Leave `BannerInstructions` and `SpecialHandling` empty and populate `CoverSheets` with a single empty string ([BR-AAC-015](../business-rules.md#br-aac-015-document-api-requests-omit-cover-sheets-and-special-handling)).
6. Attach the caller-supplied `DistributionOptions` and POST the assembled request to `/v1/distribute`.
7. Return `true` only when the response status code is `HttpStatusCode.OK` ([BR-AAC-016](../business-rules.md#br-aac-016-document-api-success-requires-http-200)).
8. If request assembly or posting throws, write the exception message to `Console` and return `false` instead of rethrowing ([BR-AAC-017](../business-rules.md#br-aac-017-document-api-exceptions-are-swallowed-and-reported-as-failure)).

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
  Start([CallDocumentApi]) --> Build[Build DistributionRequest]
  Build --> Post[POST /v1/distribute]
  Post --> Decision{HTTP 200?}
  Decision -->|Yes| Good([Return true])
  Decision -->|No| Bad([Return false])
```

## Failure and edge-case behavior

- Exceptions are swallowed after their message is written to `Console`.
- Any non-200 response is treated as unsuccessful.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [Configuration](../configuration.md)

## Sources
- `Business\SAIF.Business.Policy.Audit.ApiCalls\DocumentApiCall.cs`
