---
title: "Download document file"
description: "Downloads an available document file. For an unstamped CFDI draft, use preview_pdf to inspect the rendered PDF before stamping; the preview has no fiscal validity."
language: en
canonical_url: "https://exac.mx/docs/en/api/documents/files-and-delivery/download-document-file"
md_url: "https://exac.mx/docs/en/api/documents/files-and-delivery/download-document-file.md"
---

# Download document file

Downloads an available document file. For an unstamped CFDI draft, use preview_pdf to inspect the rendered PDF before stamping; the preview has no fiscal validity.

## Request

`GET /v1/documents/{documentRef}/files/{file}`

- **Authorization:** The document category encoded in the reference determines the required permission: `cfdi` → `invoices:read`, `withholding` → `invoices:read`, `sales_receipt` → `receipts:read`, `quote` → `quotes:read`, `declaration` → `sat:read`, `tax_compliance_opinion` → `sat:read`.

- **Environments:** Production and sandbox

- **Idempotency:** Not required

## Canonical machine contract

This fragment is generated from the canonical operation and Zod contracts used by the route.

```json
{
  "method": "GET",
  "path": "/v1/documents/{documentRef}/files/{file}",
  "operation": {
    "operationId": "downloadDocumentFile",
    "tags": [
      "Files and delivery"
    ],
    "summary": "Download document file",
    "description": "Downloads an available document file. For an unstamped CFDI draft, use preview_pdf to inspect the rendered PDF before stamping; the preview has no fiscal validity.",
    "security": [
      {
        "bearerAuth": []
      }
    ],
    "parameters": [
      {
        "name": "documentRef",
        "in": "path",
        "required": true,
        "schema": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^cfdi:.+$"
            },
            {
              "type": "string",
              "pattern": "^withholding:.+$"
            },
            {
              "type": "string",
              "pattern": "^sales_receipt:.+$"
            },
            {
              "type": "string",
              "pattern": "^quote:.+$"
            },
            {
              "type": "string",
              "pattern": "^declaration:.+$"
            },
            {
              "type": "string",
              "pattern": "^tax_compliance_opinion:.+$"
            }
          ],
          "description": "DocumentRef for a CFDI, withholding, sales receipt, quote, declaration, or tax-compliance opinion. Expenses and refunds do not have downloadable files."
        }
      },
      {
        "name": "file",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "enum": [
            "pdf",
            "xml",
            "zip",
            "preview_pdf",
            "cancellation_pdf",
            "cancellation_xml",
            "payment_pdf",
            "full_pdf"
          ],
          "description": "File selector. Use preview_pdf to render an unstamped CFDI draft before stamping. CFDIs also support pdf, xml, zip, cancellation_pdf, and cancellation_xml. Withholdings: pdf, xml, zip. Sales receipts and quotes: pdf. Declarations: pdf, payment_pdf, full_pdf. Opinions: pdf."
        }
      }
    ],
    "responses": {
      "200": {
        "description": "Operation completed.",
        "content": {
          "application/pdf": {
            "schema": {
              "type": "string",
              "format": "binary"
            }
          },
          "application/xml": {
            "schema": {
              "type": "string",
              "format": "binary"
            }
          },
          "application/zip": {
            "schema": {
              "type": "string",
              "format": "binary"
            }
          }
        },
        "headers": {
          "Request-Id": {
            "$ref": "#/components/headers/RequestId"
          },
          "Content-Disposition": {
            "description": "Disposition and filename selected by the server file contract.",
            "schema": {
              "type": "string"
            }
          }
        }
      },
      "400": {
        "description": "Invalid request.\n\n`validation_error`",
        "headers": {
          "Request-Id": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "401": {
        "description": "Missing or invalid credential.\n\n`unauthenticated`",
        "headers": {
          "Request-Id": {
            "$ref": "#/components/headers/RequestId"
          },
          "WWW-Authenticate": {
            "$ref": "#/components/headers/WWWAuthenticate"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "403": {
        "description": "The credential does not satisfy the required authorization. The document category encoded in the reference determines the required permission: `cfdi` → `invoices:read`, `withholding` → `invoices:read`, `sales_receipt` → `receipts:read`, `quote` → `quotes:read`, `declaration` → `sat:read`, `tax_compliance_opinion` → `sat:read`.\n\n`forbidden`",
        "headers": {
          "Request-Id": {
            "$ref": "#/components/headers/RequestId"
          },
          "WWW-Authenticate": {
            "$ref": "#/components/headers/WWWAuthenticate"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "404": {
        "description": "Resource not found.\n\n`not_found`",
        "headers": {
          "Request-Id": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "405": {
        "description": "Method not allowed.\n\n`method_not_allowed`",
        "headers": {
          "Request-Id": {
            "$ref": "#/components/headers/RequestId"
          },
          "Allow": {
            "$ref": "#/components/headers/Allow"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "429": {
        "description": "Too many requests.\n\n`rate_limited`",
        "headers": {
          "Request-Id": {
            "$ref": "#/components/headers/RequestId"
          },
          "Retry-After": {
            "$ref": "#/components/headers/RetryAfter"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "500": {
        "description": "Internal server error.\n\n`internal`",
        "headers": {
          "Request-Id": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "503": {
        "description": "Service temporarily unavailable.\n\n`provider_unavailable`",
        "headers": {
          "Request-Id": {
            "$ref": "#/components/headers/RequestId"
          },
          "Retry-After": {
            "$ref": "#/components/headers/RetryAfter"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      }
    },
    "x-exac-environments": [
      "production",
      "sandbox"
    ],
    "x-exac-sandbox-constraints": {
      "documentCategories": [
        "cfdi",
        "withholding",
        "sales_receipt",
        "quote"
      ]
    }
  },
  "components": {
    "schemas": {
      "ApiError": {
        "type": "object",
        "properties": {
          "error": {
            "$ref": "#/components/schemas/ProgrammaticError"
          }
        },
        "required": [
          "error"
        ],
        "additionalProperties": false
      },
      "ProgrammaticError": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "enum": [
              "validation_error",
              "unauthenticated",
              "forbidden",
              "not_found",
              "method_not_allowed",
              "conflict",
              "idempotency_conflict",
              "operation_in_progress",
              "recovery_required",
              "rate_limited",
              "provider_unavailable",
              "internal"
            ],
            "description": "Recommended action by code:\n\n- `validation_error` — Correct each details.issues entry using its path and stable issue code.\n- `unauthenticated` — Provide a valid API key or OAuth access token.\n- `forbidden` — Use a credential with the required permission.\n- `not_found` — Check the organization-scoped resource identifier.\n- `method_not_allowed` — Use the documented HTTP method.\n- `conflict` — Refresh the resource and resolve its current state.\n- `idempotency_conflict` — Use a new idempotency key for a changed request.\n- `operation_in_progress` — Wait for Retry-After, then repeat the exact request.\n- `recovery_required` — Do not retry automatically; reconcile the provider outcome.\n- `rate_limited` — Wait for Retry-After before retrying.\n- `provider_unavailable` — Retry only when the response marks the failure as retryable.\n- `internal` — Retry later and contact support if the error persists."
          },
          "message": {
            "type": "string"
          },
          "details": {
            "type": "object",
            "properties": {
              "issues": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "path": {
                      "type": "array",
                      "items": {
                        "anyOf": [
                          {
                            "type": "string"
                          },
                          {
                            "type": "number"
                          }
                        ]
                      }
                    },
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "path",
                    "message"
                  ],
                  "additionalProperties": false
                }
              },
              "retryable": {
                "type": "boolean"
              },
              "retryAfterSeconds": {
                "type": "integer",
                "exclusiveMinimum": 0,
                "maximum": 9007199254740991
              }
            },
            "additionalProperties": false
          },
          "status": {
            "type": "integer",
            "minimum": -9007199254740991,
            "maximum": 9007199254740991
          }
        },
        "required": [
          "code",
          "message",
          "status"
        ],
        "additionalProperties": false
      }
    }
  }
}
```

[OpenAPI 3.1](/openapi.json)

## Equivalent MCP tools

- [`get_document_file`](/docs/en/mcp/tools/get_document_file.md)

Complete documentation: https://exac.mx/docs/en.md
Agent documentation index: https://exac.mx/docs/en/llms.txt
