> ## Documentation Index
> Fetch the complete documentation index at: https://docs.veripay.datagora.mx/llms.txt
> Use this file to discover all available pages before exploring further.

# Ejemplos por lenguaje

> Snippets listos para copiar en curl, Python, Node.js, Go y PHP.

Todos los ejemplos asumen `VERIPAY_KEY` cargada como variable de entorno.

## CEP en XML (modo auto)

<CodeGroup>
  ```bash curl theme={null}
  curl -sS -X POST "https://veripay.datagora.mx/api/v1/cep/xml_auto" \
    -H "Content-Type: application/json" \
    -H "x-api-key: $VERIPAY_KEY" \
    -d '{
      "fecha": "2025-08-15",
      "clave_rastreo": "CR12345678",
      "cuenta": "012180001234567890",
      "monto": 1234.56
    }' \
    --output cep.xml
  ```

  ```python python theme={null}
  import os, requests

  resp = requests.post(
      "https://veripay.datagora.mx/api/v1/cep/xml_auto",
      headers={"x-api-key": os.environ["VERIPAY_KEY"]},
      json={
          "fecha": "2025-08-15",
          "clave_rastreo": "CR12345678",
          "cuenta": "012180001234567890",
          "monto": 1234.56,
      },
      timeout=15,
  )
  resp.raise_for_status()
  open("cep.xml", "wb").write(resp.content)
  print("inferred_emisor:", resp.headers.get("x-inferred-emisor"))
  ```

  ```javascript node theme={null}
  import { writeFileSync } from "node:fs";

  const res = await fetch("https://veripay.datagora.mx/api/v1/cep/xml_auto", {
    method: "POST",
    headers: {
      "content-type": "application/json",
      "x-api-key": process.env.VERIPAY_KEY,
    },
    body: JSON.stringify({
      fecha: "2025-08-15",
      clave_rastreo: "CR12345678",
      cuenta: "012180001234567890",
      monto: 1234.56,
    }),
  });
  if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
  writeFileSync("cep.xml", Buffer.from(await res.arrayBuffer()));
  ```

  ```go go theme={null}
  package main

  import (
    "bytes"
    "fmt"
    "io"
    "net/http"
    "os"
  )

  func main() {
    body := bytes.NewBufferString(`{"fecha":"2025-08-15","clave_rastreo":"CR12345678","cuenta":"012180001234567890","monto":1234.56}`)
    req, _ := http.NewRequest("POST", "https://veripay.datagora.mx/api/v1/cep/xml_auto", body)
    req.Header.Set("content-type", "application/json")
    req.Header.Set("x-api-key", os.Getenv("VERIPAY_KEY"))
    res, err := http.DefaultClient.Do(req)
    if err != nil { panic(err) }
    defer res.Body.Close()
    if res.StatusCode != 200 {
      msg, _ := io.ReadAll(res.Body)
      panic(fmt.Sprintf("%d: %s", res.StatusCode, msg))
    }
    data, _ := io.ReadAll(res.Body)
    os.WriteFile("cep.xml", data, 0644)
  }
  ```

  ```php php theme={null}
  <?php
  $payload = json_encode([
    'fecha' => '2025-08-15',
    'clave_rastreo' => 'CR12345678',
    'cuenta' => '012180001234567890',
    'monto' => 1234.56,
  ]);

  $ch = curl_init('https://veripay.datagora.mx/api/v1/cep/xml_auto');
  curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
      'Content-Type: application/json',
      'x-api-key: ' . getenv('VERIPAY_KEY'),
    ],
  ]);
  $xml = curl_exec($ch);
  file_put_contents('cep.xml', $xml);
  ```
</CodeGroup>

## CEP en PDF

<CodeGroup>
  ```bash curl theme={null}
  curl -sS -X POST "https://veripay.datagora.mx/api/v1/cep/pdf_auto" \
    -H "x-api-key: $VERIPAY_KEY" \
    -H "Content-Type: application/json" \
    -d '{"fecha":"2025-08-15","clave_rastreo":"CR12345678","cuenta":"012180001234567890","monto":1234.56}' \
    --output cep.pdf
  ```

  ```python python theme={null}
  import os, requests

  resp = requests.post(
      "https://veripay.datagora.mx/api/v1/cep/pdf_auto",
      headers={"x-api-key": os.environ["VERIPAY_KEY"]},
      json={
          "fecha": "2025-08-15",
          "clave_rastreo": "CR12345678",
          "cuenta": "012180001234567890",
          "monto": 1234.56,
      },
  )
  resp.raise_for_status()
  open("cep.pdf", "wb").write(resp.content)
  ```
</CodeGroup>

## ZIP (PDF + XML en una sola llamada)

```bash theme={null}
curl -sS -X POST "https://veripay.datagora.mx/api/v1/cep/zip_auto" \
  -H "x-api-key: $VERIPAY_KEY" \
  -H "Content-Type: application/json" \
  -d '{"fecha":"2025-08-15","clave_rastreo":"CR12345678","cuenta":"012180001234567890","monto":1234.56}' \
  --output cep.zip
```

## Base64 (cliente sin soporte binario)

```bash theme={null}
curl -sS -X POST "https://veripay.datagora.mx/api/v1/cep/base64" \
  -H "x-api-key: $VERIPAY_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "fecha":"2025-08-15",
    "clave_rastreo":"CR12345678",
    "emisor":"40012",
    "receptor":"40021",
    "cuenta":"012180001234567890",
    "monto":1234.56
  }'
```

```json theme={null}
{
  "ok": true,
  "filename": "cep.pdf",
  "content_type": "application/pdf",
  "data": "JVBERi0xLjQKJeLjz9MK..."
}
```
