Rutas de integración disponibles
API REST + Webhooks
Total control desde su backend (cotizaciones, creación de envíos, etiquetas, tracking y eventos).
- Autenticación Bearer
- Webhooks firmados (HMAC)
- Ejemplos en PHP
Shopify
Sincronice pedidos y fulfillment, con reglas para COD y notificaciones.
- Importación de pedidos
- Actualización de estados
- Webhooks Shopify
Integración vía API REST
Solicitar accesoEntorno y autenticación
- Base URL (ejemplo): https://api.logihub.tech/v1/
- Auth: Authorization: Bearer <TOKEN>
- Content-Type: application/json
- Webhooks firmados: X-LogiHUB-Signature: sha256=...
Variables .env
(ejemplo):
LOGIHUB_API_URL=https://api.logihub.tech/v1
LOGIHUB_API_TOKEN=su_token_empresarial
LOGIHUB_WEBHOOK_SECRET=su_secreto_webhook
Endpoints (ejemplos)
{
"origen": {"ciudad": "Santo Domingo", "pais": "DO"},
"destino": {"ciudad": "Santiago", "pais": "DO"},
"paquete": {"peso_lb": 3, "largo_cm": 30, "ancho_cm": 20, "alto_cm": 15},
"servicio": "estandar",
"cod": {"monto": 1200, "habilitado": true}
}
{
"remitente": {...},
"destinatario": {...},
"paquete": {...},
"servicio": "estandar",
"cod": {"monto": 1200, "habilitado": true},
"referencia": "PED-100238"
}
Etiqueta: GET /shipments/{tracking}/label?format=pdf
{
"tracking": "DO123456789",
"status": "in_transit",
"eta": "2025-08-08",
"history": [...]
}
PHP — Cotización
<?php
$api = getenv('LOGIHUB_API_URL');
$token = getenv('LOGIHUB_API_TOKEN');
$payload = [
"origen" => ["ciudad" => "Santo Domingo", "pais" => "DO"],
"destino" => ["ciudad" => "Santiago", "pais" => "DO"],
"paquete" => ["peso_lb" => 3, "largo_cm" => 30, "ancho_cm" => 20, "alto_cm" => 15],
"servicio" => "estandar",
"cod" => ["monto" => 1200, "habilitado" => true]
];
$ch = curl_init("$api/rates/quote");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer $token", "Content-Type: application/json"],
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$res = curl_exec($ch);
if ($res === false) { http_response_code(500); die(curl_error($ch)); }
curl_close($ch);
header('Content-Type: application/json'); echo $res;
PHP — Crear envío y etiqueta
<?php
$api = getenv('LOGIHUB_API_URL');
$token = getenv('LOGIHUB_API_TOKEN');
$shipment = [
"remitente" => ["nombre" => "Mi Empresa", "telefono" => "+1 809 ...", "direccion" => "Calle X 123, SD"],
"destinatario"=> ["nombre" => "Cliente", "telefono" => "+1 809 ...", "direccion" => "Av. Y 456, Santiago"],
"paquete" => ["peso_lb" => 2, "largo_cm" => 25, "ancho_cm" => 18, "alto_cm" => 12, "contenido" => "Textiles"],
"servicio" => "estandar",
"cod" => ["monto" => 950, "habilitado" => true],
"referencia" => "PED-100239"
];
function api_post($url, $token, $data){
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer $token", "Content-Type: application/json"],
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($data),
]);
$res = curl_exec($ch);
if ($res === false) throw new Exception(curl_error($ch));
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($code >= 400) throw new Exception("HTTP $code: $res");
return json_decode($res, true);
}
try {
$r = api_post("$api/shipments", $token, $shipment);
$tracking = $r['tracking'] ?? null;
if (!$tracking) throw new Exception("Sin tracking");
// Descargar etiqueta PDF
$labelUrl = "$api/shipments/$tracking/label?format=pdf";
$ch = curl_init($labelUrl);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer $token"],
]);
$pdf = curl_exec($ch);
curl_close($ch);
file_put_contents(__DIR__."/label_$tracking.pdf", $pdf);
echo "OK. Tracking: $tracking. Etiqueta: label_$tracking.pdf";
} catch (Exception $e) {
http_response_code(500); echo "Error: ".$e->getMessage();
}
PHP — Webhook (verificación HMAC)
<?php
$secret = getenv('LOGIHUB_WEBHOOK_SECRET');
$payload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_LOGIHUB_SIGNATURE'] ?? '';
if (!preg_match('/^sha256=([a-f0-9]{64})$/', $signature, $m)) {
http_response_code(400); exit('Firma inválida');
}
$calc = 'sha256=' . hash_hmac('sha256', $payload, $secret);
if (!hash_equals($calc, $signature)) {
http_response_code(401); exit('No autorizado');
}
$data = json_decode($payload, true);
$event = $data['event'] ?? 'unknown';
switch ($event) {
case 'shipment.delivered':
// Actualizar su ERP/tienda, cerrar orden, notificar cliente
break;
case 'shipment.exception':
// Abrir incidencia en su sistema
break;
case 'cod.settled':
// Registrar liquidación COD en finanzas
break;
}
http_response_code(200); echo 'OK';
Integración con Shopify
Solicitar instalaciónPasos de conexión (resumen)
- Crear App en Shopify (o instalar la app de LogiHUB si corresponde a su plan/tienda).
- Generar credenciales: Admin API Access Token y Shared Secret.
- Configurar Webhooks: orders/create, orders/paid, fulfillments/create/update, app/uninstalled.
- Mapeo de servicios: métodos de envío ↔ servicios LogiHUB; reglas de COD.
- Definir flujo: fulfillment automático o manual; etiquetas y notas internas.
- Pruebas: pedido de prueba, ver tracking y actualización de estado.
Nota: Algunas funciones como tarifas en tiempo real (CarrierService) requieren planes avanzados en Shopify.
Checklist técnico
- Dominio de tienda (
mi-tienda.myshopify.com
) - Admin Access Token y Shared Secret seguros
- URL pública para webhooks de LogiHUB
- Reglas para COD (tags, atributos o método de pago)
- Política de etiquetas e impresoras (si aplica)
- Plan de reversos/devoluciones
PHP — Verificar Webhook de Shopify
<?php
// X-Shopify-Hmac-Sha256 (HMAC SHA256 con el "Shared Secret" de su App)
$secret = getenv('SHOPIFY_SHARED_SECRET');
$payload = file_get_contents('php://input');
$hmacHeader = $_SERVER['HTTP_X_SHOPIFY_HMAC_SHA256'] ?? '';
$calc = base64_encode(hash_hmac('sha256', $payload, $secret, true));
if (!hash_equals($calc, $hmacHeader)) {
http_response_code(401); exit('Firma inválida');
}
$topic = $_SERVER['HTTP_X_SHOPIFY_TOPIC'] ?? 'unknown';
$shop = $_SERVER['HTTP_X_SHOPIFY_SHOP_DOMAIN'] ?? 'unknown';
$data = json_decode($payload, true);
// Ejemplo mínimo
if ($topic === 'orders/create') {
// Crear pre-guía en LogiHUB o colocar en cola para cotizar y crear envío
}
http_response_code(200); echo 'OK';
PHP — Marcar fulfillment en Shopify
<?php
$store = getenv('SHOPIFY_STORE'); // p.ej. mi-tienda.myshopify.com
$token = getenv('SHOPIFY_ADMIN_TOKEN'); // Admin API Access Token
$orderId = '1234567890'; // Shopify order ID (numérico)
$tracking = 'DO123456789'; // Tracking de LogiHUB
$trackingUrl = "https://logihub.tech/tracking/$tracking";
$payload = [
"fulfillment" => [
"tracking_numbers" => [$tracking],
"tracking_urls" => [$trackingUrl],
"notify_customer" => true,
// "line_items_by_fulfillment_order" => [...] // en flujos FO
]
];
$ch = curl_init("https://$store/admin/api/2024-10/orders/$orderId/fulfillments.json");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"X-Shopify-Access-Token: $token",
"Content-Type: application/json"
],
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$res = curl_exec($ch);
if ($res === false) { http_response_code(500); die(curl_error($ch)); }
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($code >= 400) { http_response_code($code); die($res); }
echo 'Fulfillment enviado.';
Variables de entorno Shopify
SHOPIFY_STORE=mi-tienda.myshopify.com
SHOPIFY_ADMIN_TOKEN=shpat_xxxxxxxxxxxxxxxxxxxxxxxxx
SHOPIFY_SHARED_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Guarde estos valores de manera segura. El Shared Secret se usa para validar webhooks.
Asistencia para la integración
WhatsApp (prioritario): +1 809 991 9972
Correo: hola@logihub.tech
Cita técnica: /Cita-comercial/
Solicitud prellenada
Nuestro equipo técnico lo acompaña en pruebas, mapeos y puesta en producción. También ofrecemos soporte para flujos avanzados (CarrierService, multi-bodega, reglas COD, devoluciones y analítica).