# Export report to PDF

The **Export Report to PDF** endpoint exports a generated mortgage report to PDF format and returns a downloadable PDF file URL.

## Request

---

- Type: **`POST`**
- Path: **`/engine/export-report-pdf`**

---

### Endpoint

The Export Report to PDF endpoint can be accessed from the following URLs:

<table border="1" id="bkmrk-environment-api-base" style="border-collapse: collapse; width: 100%; border-width: 1px; height: 113.391px;"><colgroup><col style="width: 28.3334%;"></col><col style="width: 71.7902%;"></col></colgroup><thead><tr style="height: 37.7969px;"><td style="padding: 10px; height: 37.7969px;">**Environment**</td><td style="padding: 10px; height: 37.7969px;">**Endpoint URL**</td></tr></thead><tbody><tr style="height: 37.7969px;"><td style="padding: 10px; height: 37.7969px;">Test</td><td style="padding: 10px; height: 37.7969px;">`https://api.mre.test.blackfin.tools/engine/export-report-pdf`</td></tr><tr style="height: 37.7969px;"><td style="padding: 10px; height: 37.7969px;">Production</td><td style="padding: 10px; height: 37.7969px;">`<a href="https://api.mre.blackfin.tools/engine/export-report-pdf">https://api.mre.blackfin.tools/engine/export-report-pdf</a>` **(NOT LIVE)**</td></tr></tbody></table>

---

#### Authentication

An `API_Key` is required to call this endpoint. [HTTP Bearer Token authentication](https://docs.blackfin.tools/books/mortgagerecenginemycrm/page/integration#bkmrk-authentication) is used.

---

### JSON Schema

The request payload is sent as HTTP JSON body using the following schema:

```json
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "title": "Export Report to PDF Request",
  "description": "Request payload for exporting a generated mortgage report to PDF format",
  "properties": {
    "reportId": {
      "type": "string",
      "description": "ID of the report to export",
      "minLength": 1
    },
    "lenders": {
      "type": "array",
      "description": "Array of lender codes to include in the PDF",
      "items": {
        "type": "string",
        "enum": [
          "aia",
          "anz", 
          "asb",
          "bnz",
          "co-op",
          "kiwibank",
          "liberty",
          "sbs",
          "tsb",
          "westpac"
        ]
      },
      "minItems": 1,
      "uniqueItems": true
    },
    "currentLoanAmount": {
      "type": "number",
      "description": "Optional override for loan amount",
      "minimum": 0
    },
    "includeWarningsErrors": {
      "type": "boolean",
      "description": "Whether to include warnings and errors in the PDF",
      "default": false
    },
    "notes": {
      "type": "string",
      "description": "Optional notes to include in the PDF",
      "maxLength": 5000
    }
  },
  "required": [
    "reportId",
    "lenders"
  ],
  "additionalProperties": false
}
```

---

#### Examples

Example request payload:

<details id="bkmrk-example-1%3A-json-requ"><summary>JSON Request Body</summary>

```json
{
  "reportId": "abc123def456",
  "lenders": ["anz", "asb", "westpac"],
  "currentLoanAmount": 500000,
  "includeWarningsErrors": true,
  "notes": "Custom notes for this PDF export"
}
```

</details>---

#### Validation

The API performs validation on the request payload:

- `reportId` and `lenders` are required fields
- `lenders` must be a non-empty array with valid lender codes
- `currentLoanAmount` must be a positive number if provided
- `notes` cannot exceed 5000 characters

---

## Response

---

### Success

If the Export Report to PDF completes successfully:

#### JSON Body

```json
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "title": "Export Report to PDF Response",
  "description": "Response payload for the export report to PDF operation",
  "properties": {
    "url": {
      "type": "string",
      "description": "Signed download URL for the generated PDF file (valid for 24 hours)",
      "format": "uri",
      "pattern": "^https://",
      "example": "https://storage.googleapis.com/project.appspot.com/pdf_reports/abc123def456.pdf?GoogleAccessId=...&Expires=1691234567&Signature=..."
    }
  },
  "required": [
    "url"
  ],
  "additionalProperties": false
}
```

#### Examples

<p class="callout success">**200**: Success</p>

<details id="bkmrk-example-1%3A-label-%C2%A0"><summary>Success Response</summary>

```json
{
  "url": "https://storage.googleapis.com/project.appspot.com/pdf_reports/abc123def456.pdf?GoogleAccessId=...&Expires=1691234567&Signature=..."
}
```

</details>---

### Error

If errors are encountered during the Export Report to PDF operation:

#### JSON Body

```
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "error": {
      "type": "object",
      "description": "Error information",
      "properties": {
        "message": {
          "type": "string",
          "description": "Human readable error message"
        },
        "status": {
          "type": "string",
          "description": "Error code in uppercase letters and _ as space",
          "enum": ["INVALID_ARGUMENT","NOT_FOUND","INTERNAL_ERROR","METHOD_NOT_ALLOWED","UNAUTHENTICATED"]
        }
      }
    }
  }
}
```


#### Examples

<p class="callout danger">**400**: Bad Request</p>

<details id="bkmrk-example-1%3A-missing-a"><summary>Invalid input</summary>

```json
{
    "error": {
        "message": "Invalid input: reportId and lenders are required",
        "status": "INVALID_ARGUMENT"
    }
}
```

</details><p class="callout danger">**401**: Missing API Key</p>

<details id="bkmrk-example-missing-api-key"><summary>Missing API Key</summary>

```json
{
    "error": {
        "message": "Missing API Key",
        "status": "UNAUTHENTICATED"
    }
}
```

</details><p class="callout danger">**401**: Invalid API Key</p>

<details id="bkmrk-example-invalid-api-key"><summary>Invalid API Key</summary>

```json
{
    "error": {
        "message": "Invalid API Key",
        "status": "UNAUTHENTICATED"
    }
}
```

</details><p class="callout danger">**404**: Report Not Found</p>

<details id="bkmrk-example-2%3A-invalid-a"><summary>Report not found</summary>

```json
{
    "error": {
        "message": "Report not found",
        "status": "NOT_FOUND"
    }
}
```

</details><p class="callout danger">**405**: Method Not Allowed</p>

<details id="bkmrk-example-3%3A-invalid-d"><summary>Method not allowed</summary>

```json
{
    "error": {
        "message": "Method Not Allowed",
        "status": "METHOD_NOT_ALLOWED"
    }
}
```

</details><details id="bkmrk-invalid-data%3A-invali"><summary>Internal Server Error</summary>

**500**: Internal Server Error

```json
{
    "error": {
        "message": "Error generating PDF",
        "status": "INTERNAL_ERROR"
    }
}
```

</details>