Ejemplos
Recetas listas para copiar sobre casos comunes con la API de Falconext.
Recetas cortas para tareas comunes. Cópialas y adáptalas a tu proyecto.
Crear un pedido
orders.create
import { FalconextLogistica } from "@falconext/logistica";
const fx = new FalconextLogistica({ apiKey: process.env.FALCONEXT_API_KEY });
const order = await fx.orders.create({
externalOrderId: "ORD-10482",
customer: { name: "María Fernández", phone: "+51987654321" },
deliveryAddress: { address: "Calle Los Pinos 120, Miraflores", city: "Lima" },
items: [{ description: "Polo talla M", quantity: 2 }],
cashOnDelivery: 120.0,
});
console.log(order.trackingCode);Listar pedidos en tránsito
Terminal
curl "https://api.falconext.pe/api/v1/logistics/orders?status=in_transit&limit=20" \
-H "Authorization: Bearer $FALCONEXT_API_KEY"Recibir y verificar un webhook (Express)
JavaScript
import express from "express";
import { verifySignature } from "./verify.js";
const app = express();
app.post("/webhooks/falconext",
express.raw({ type: "application/json" }),
(req, res) => {
const signature = req.header("Falconext-Signature");
if (!verifySignature(req.body, signature, process.env.WEBHOOK_SECRET)) {
return res.status(400).send("firma inválida");
}
const event = JSON.parse(req.body);
if (event.event === "order.delivered") {
// marca la orden como entregada
}
res.sendStatus(200);
},
);Cancelar un pedido
Terminal
curl -X POST https://api.falconext.pe/api/v1/logistics/orders/ord_3xK8p2Qm/cancel \
-H "Authorization: Bearer $FALCONEXT_API_KEY"