Inicio rápido

API de Revendedores

1. Crear una clave API

Acceda al portal de clientes, sección "API de Revendedores" y cree una clave. Active únicamente los permisos que realmente necesite (por defecto, solo lectura). El secreto se muestra una sola vez; guárdelo de forma segura en su gestor de secretos.

2. Almacenar las credenciales

Guarde la clave y el secreto como variables de entorno. Nunca en el código, nunca en un repositorio.

# .env o perfil de shell
export KH_KEY="kh_live_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
export KH_SECRET="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

3. Enviar su primera petición

Liste los productos disponibles. La firma se construye sobre método, ruta, marca de tiempo, nonce y hash del cuerpo.

TS=$(date +%s)
NONCE=$(openssl rand -hex 16)
BODY_SHA256=$(printf '' | openssl dgst -sha256 -hex | awk '{print $2}')
SIG_INPUT=$(printf 'GET\n/v1/products\n%s\n%s\n%s' "$TS" "$NONCE" "$BODY_SHA256")
SIG=$(printf '%s' "$SIG_INPUT" | openssl dgst -sha256 -hmac "$KH_SECRET" -hex | awk '{print $2}')

curl https://www.kernelhost.com/cp/kh_reseller_api/v1/products \
  -H "KH-Key: $KH_KEY" \
  -H "KH-Timestamp: $TS" \
  -H "KH-Nonce: $NONCE" \
  -H "KH-Signature: $SIG"

4. Realizar un pedido

Importante: POST /v1/orders requiere un Idempotency-Key. Ante un reintento de red con la misma clave, recibirá la misma respuesta, sin que se genere un pedido duplicado.

BODY='{"product_id":42,"billing_cycle":"monthly"}'
BODY_SHA256=$(printf '%s' "$BODY" | openssl dgst -sha256 -hex | awk '{print $2}')
TS=$(date +%s)
NONCE=$(openssl rand -hex 16)
IDEM=$(openssl rand -hex 16)
SIG_INPUT=$(printf 'POST\n/v1/orders\n%s\n%s\n%s' "$TS" "$NONCE" "$BODY_SHA256")
SIG=$(printf '%s' "$SIG_INPUT" | openssl dgst -sha256 -hmac "$KH_SECRET" -hex | awk '{print $2}')

curl -X POST https://www.kernelhost.com/cp/kh_reseller_api/v1/orders \
  -H "KH-Key: $KH_KEY" \
  -H "KH-Timestamp: $TS" \
  -H "KH-Nonce: $NONCE" \
  -H "KH-Signature: $SIG" \
  -H "Idempotency-Key: $IDEM" \
  -H "Content-Type: application/json" \
  --data "$BODY"

5. Configurar un webhook (opcional)

Registre una URL HTTPS por clave para recibir eventos de forma asíncrona (order.paid, service.provisioned, invoice.created). La firma del payload sigue el esquema de Stripe.