Descargar CDR
Descarga la constancia de recepción (CDR) que devolvió SUNAT.
Autenticación: token Bearer de empresa (cpe:sign).
Ejemplo
Copiar
curl -X GET https://api.xmlperu.dev/v1/cpe/9c2f1b7e-0000-0000-0000-000000000000/cdr?formato=xml \
-H "Authorization: Bearer $TOKEN_EMPRESA" \
-H "Accept: application/json"Copiar
<?php
$token_empresa = 'pega-aqui-tu-token';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.xmlperu.dev/v1/cpe/9c2f1b7e-0000-0000-0000-000000000000/cdr?formato=xml');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token_empresa,
'Accept: application/json',
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);Copiar
const TOKEN_EMPRESA = 'pega-aqui-tu-token';
const res = await fetch('https://api.xmlperu.dev/v1/cpe/9c2f1b7e-0000-0000-0000-000000000000/cdr?formato=xml', {
method: 'GET',
headers: {
Authorization: `Bearer ${TOKEN_EMPRESA}`,
Accept: 'application/json',
},
});
const data = await res.json();Copiar
import requests
TOKEN_EMPRESA = "pega-aqui-tu-token"
headers = {
"Authorization": f"Bearer {TOKEN_EMPRESA}",
"Accept": "application/json",
}
res = requests.get("https://api.xmlperu.dev/v1/cpe/9c2f1b7e-0000-0000-0000-000000000000/cdr?formato=xml", headers=headers)
data = res.json()Copiar
using System.Net.Http;
using System.Net.Http.Headers;
var tokenEmpresa = "pega-aqui-tu-token";
using var client = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.xmlperu.dev/v1/cpe/9c2f1b7e-0000-0000-0000-000000000000/cdr?formato=xml");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokenEmpresa);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
using var response = await client.SendAsync(request);
var data = await response.Content.ReadAsStringAsync();Parámetros
En la URL
| Nombre | Tipo | Descripción |
|---|---|---|
| external_id* | string | Identificador del comprobante devuelto al emitir. |
En la consulta (?a=b)
| Nombre | Tipo | Descripción |
|---|---|---|
| formato | string | Deja vacío para el ZIP de SUNAT (por defecto). xml devuelve el XML extraído. |
* Obligatorio.
Ten en cuenta
- La respuesta es un archivo ZIP, no un JSON. Es el mismo ZIP que entrega SUNAT.
- Con
?formato=xmldevuelve solo el XML de dentro. - Está disponible cuando el comprobante tiene
has_cdr: true. Míralo en Consultar. - Sirve para cualquier documento: facturas, boletas, notas, resúmenes y guías.
Qué contiene el ZIP
R-20123456789-01-F001-42.zip
├── dummy/
└── R-20123456789-01-F001-42.xml
La carpeta dummy/ va vacía. Es parte del formato de SUNAT.
Ejemplos
# El ZIP
curl https://api.xmlperu.dev/v1/cpe/$EXTERNAL_ID/cdr \
-H "Authorization: Bearer $TOKEN" -o cdr.zip
# Solo el XML
curl "https://api.xmlperu.dev/v1/cpe/$EXTERNAL_ID/cdr?formato=xml" \
-H "Authorization: Bearer $TOKEN" -o cdr.xml
Errores
404 No existeapplication/json
{
"success": false,
"message": "El comprobante no existe."
}