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

# cURL

> Ejemplos con cURL para terminal y scripts.

# cURL

## Archivo local

```bash theme={null}
curl -X POST "https://api.markpdf.tech/convert/raw?filename=informe.pdf&mode=fast" \
  -H "x-api-key: TU_API_KEY" \
  -H "content-type: application/pdf" \
  --data-binary @informe.pdf
```

## URL firmada

```bash theme={null}
curl -X POST "https://api.markpdf.tech/convert/from-url" \
  -H "x-api-key: TU_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "url": "https://bucket.s3.amazonaws.com/informe.pdf?X-Amz-Signature=...",
    "filename": "informe.pdf",
    "mode": "fast"
  }'
```

## Respuesta JSON

```bash theme={null}
curl -X POST "https://api.markpdf.tech/convert/raw?filename=informe.pdf&mode=fast&response_format=json" \
  -H "x-api-key: TU_API_KEY" \
  -H "content-type: application/pdf" \
  --data-binary @informe.pdf | jq .
```

## Manejo de 202 (auto-async)

Script bash completo que maneja 202 automáticamente:

```bash theme={null}
#!/usr/bin/env bash
set -euo pipefail

API_URL="https://api.markpdf.tech"
API_KEY="TU_API_KEY"
FILE="$1"

# Enviar conversión
HTTP_CODE=$(curl -s -o /tmp/flash-response.json -w "%{http_code}" \
  -X POST "${API_URL}/convert/raw?filename=$(basename "$FILE")&mode=fast" \
  -H "x-api-key: ${API_KEY}" \
  -H "content-type: application/pdf" \
  --data-binary "@${FILE}")

if [ "$HTTP_CODE" = "200" ]; then
  cat /tmp/flash-response.json
  exit 0
fi

if [ "$HTTP_CODE" = "202" ]; then
  JOB_ID=$(jq -r '.job_id' /tmp/flash-response.json)
  DELAY=$(jq -r '.retry_after_seconds // 5' /tmp/flash-response.json)
  echo "Encolado como job ${JOB_ID}, polling cada ${DELAY}s..." >&2

  while true; do
    sleep "$DELAY"
    STATUS=$(curl -s "${API_URL}/jobs/${JOB_ID}" -H "x-api-key: ${API_KEY}")
    STATE=$(echo "$STATUS" | jq -r '.status')

    case "$STATE" in
      completed)
        echo "$STATUS" | jq -r '.body'
        exit 0
        ;;
      failed)
        echo "Error: $(echo "$STATUS" | jq -r '.error')" >&2
        exit 1
        ;;
      *)
        echo "Estado: ${STATE}..." >&2
        ;;
    esac
  done
fi

echo "Error HTTP ${HTTP_CODE}:" >&2
cat /tmp/flash-response.json >&2
exit 1
```

Uso:

```bash theme={null}
chmod +x convert.sh
./convert.sh informe.pdf > resultado.md
```

## Consultar estado de un job

```bash theme={null}
curl -s "https://api.markpdf.tech/jobs/JOB_ID_AQUI" \
  -H "x-api-key: TU_API_KEY" | jq .
```
