Skip to main content
GET
/
api
/
v1
/
invoices
/
{id}
/
download-cdr
Download CDR
curl --request GET \
  --url https://api.example.com/api/v1/invoices/{id}/download-cdr
{
  "success": true,
  "message": "<string>"
}
Downloads the CDR (Constancia de Recepción) file for an invoice or boleta. The CDR is SUNAT’s official receipt confirming that the electronic document was received and validated.
This endpoint works for both invoices and boletas. Use /api/v1/invoices/{id}/download-cdr for invoices and /api/v1/boletas/{id}/download-cdr for boletas.

Authentication

This endpoint requires authentication using a Bearer token (Sanctum).
Authorization: Bearer YOUR_API_TOKEN

Path Parameters

id
integer
required
The ID of the invoice or boleta whose CDR file you want to download.

Response

Success Response

Returns the CDR file as a ZIP download with appropriate headers:
  • Content-Type: application/zip
  • Content-Disposition: attachment; filename="R-{ruc}-{tipo}-{serie}-{numero}.zip"
The ZIP file contains an XML file with SUNAT’s response, including:
  • Response code (0 = accepted)
  • Response description
  • Digest value (hash)
  • Response date and time
  • Document reference (RUC, document type, series, number)

Error Response

success
boolean
Always false for error responses.
message
string
Error message describing why the CDR couldn’t be downloaded.

Request Examples

curl -X GET https://api.example.com/api/v1/invoices/123/download-cdr \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -O -J

Response Examples

{
  "success": false,
  "message": "CDR no encontrado"
}

CDR File Naming Convention

The downloaded CDR file follows SUNAT’s naming convention:
R-{RUC}-{TIPO_DOC}-{SERIE}-{NUMERO}.zip
Examples:
  • Invoice CDR: R-20987654321-01-F001-456.zip
  • Boleta CDR: R-20987654321-03-B001-1523.zip
The “R-” prefix stands for “Respuesta” (Response). Where:
  • RUC: Company’s tax identification number
  • TIPO_DOC: Document type code (01=Invoice, 03=Boleta)
  • SERIE: Document series
  • NUMERO: Document number

CDR XML Content

Inside the ZIP file, you’ll find an XML file named like: R-{RUC}-{TIPO_DOC}-{SERIE}-{NUMERO}.xml The XML contains:

Response Information

<cbc:ResponseCode>0</cbc:ResponseCode>
<cbc:Description>La Factura numero F001-456, ha sido aceptada</cbc:Description>
Common Response Codes:
  • 0: Accepted (Aceptado)
  • 0001-0099: Accepted with observations
  • 2000-4999: Rejected (see SUNAT error catalog)

Document Reference

<cac:DocumentReference>
    <cbc:ID>F001-456</cbc:ID>
</cac:DocumentReference>

Digest Value

<ds:DigestValue>Xj3kL9mP2qR5vW8zA1bC4dE7fG0hI=</ds:DigestValue>
This is the hash of the original XML, used to verify document integrity.

Response Date/Time

<cbc:ResponseDate>2024-03-15</cbc:ResponseDate>
<cbc:ResponseTime>10:35:22</cbc:ResponseTime>
The exact date and time SUNAT processed the document.

When is the CDR Available?

The CDR file is received when:
  1. You call the Send to SUNAT endpoint
  2. SUNAT successfully processes the document (accepted or rejected)
  3. The API receives and stores the CDR response
The CDR won’t exist if:
  • The document hasn’t been sent to SUNAT yet
  • SUNAT’s service is down and couldn’t process the request
  • There was a network error during submission
  • The document is in PENDIENTE status
Important for Compliance:Peru’s tax authority (SUNAT) requires you to store the CDR file along with the XML for at least 5 years. The CDR serves as legal proof that:
  • The document was sent to SUNAT
  • SUNAT validated and accepted the document
  • The document has legal validity
Without the CDR, the electronic document may not be considered valid for tax purposes.

CDR Status Validation

To check if a CDR is available before downloading:
  1. Get the document details via the show endpoint
  2. Check the estado_sunat field:
    • ACEPTADO: CDR available
    • RECHAZADO: CDR available (with rejection details)
    • PENDIENTE: CDR not available yet
  3. Check if cdr_path field is not null

Use Cases

  • Legal Compliance: Archive CDR files as required by SUNAT regulations
  • Proof of Acceptance: Provide CDR to customers as proof the invoice is valid
  • Audit Trail: Maintain complete records of SUNAT responses
  • Dispute Resolution: Use CDR to verify document acceptance in case of disputes
  • Integration: Share CDR with accounting or ERP systems
  • Validation: Extract and verify the digest value matches your XML

Troubleshooting

CDR Not Found

If you receive a “CDR no encontrado” error:
  1. Verify the document was sent to SUNAT using the show endpoint
  2. Check the estado_sunat field - should be ACEPTADO or RECHAZADO
  3. Confirm enviado_sunat is true
  4. If the document is PENDIENTE, call Send to SUNAT first

Storage Issues

If you receive storage errors:
  1. Verify storage disk configuration
  2. Check file permissions
  3. Ensure storage path exists
  4. Verify disk space availability

Build docs developers (and LLMs) love