Autenticación
Las APIs de KaruGO usan OAuth 2.0 con el flujo client credentials. Su aplicación
intercambia client_id y client_secret por un token de acceso que se envía en cada
llamada.
Obtener el token
POST /oauth/token
curl -X POST https://merchant-api.karugo.com.py/v1/oauth/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d grant_type=client_credentials \
-d client_id=$KARUGO_CLIENT_ID \
-d client_secret=$KARUGO_CLIENT_SECRET \
-d "scope=orders:read orders:write events:read"
200 OK
{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9…",
"token_type": "Bearer",
"expires_in": 21600,
"scope": "orders:read orders:write events:read"
}
Usar el token
Envíe el token en el header Authorization de todas las llamadas:
curl https://merchant-api.karugo.com.py/v1/merchants \
-H "Authorization: Bearer $TOKEN"
Buenas prácticas
- Reutilice el token durante sus 6 horas de validez. Renuévelo cuando falten unos minutos
para que venza, o al recibir un
401. - Pida solo los scopes que necesita.
- El
client_secretnunca debe estar en apps móviles, en el navegador ni en el repositorio. - Si sospecha que un secreto se filtró, rótelo de inmediato desde la consola.
Scopes
| Scope | Permite |
|---|---|
merchant:read | Leer tiendas, estado y horarios |
merchant:write | Abrir/cerrar tiendas y editar horarios |
catalog:read | Leer el catálogo |
catalog:write | Editar categorías, productos, precios y disponibilidad |
orders:read | Leer pedidos |
orders:write | Cambiar el estado de los pedidos |
events:read | Recibir y confirmar eventos |
shipping:read | Consultar envíos |
shipping:write | Cotizar, crear y cancelar envíos |
Ejemplo: caché del token (Node.js)
let cached = null;
async function getToken() {
const now = Date.now();
if (cached && cached.expiresAt - 5 * 60_000 > now) return cached.token;
const res = await fetch('https://merchant-api.karugo.com.py/v1/oauth/token', {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: new URLSearchParams({
grant_type: 'client_credentials',
client_id: process.env.KARUGO_CLIENT_ID,
client_secret: process.env.KARUGO_CLIENT_SECRET,
}),
});
if (!res.ok) throw new Error(`Auth falló: ${res.status}`);
const data = await res.json();
cached = {token: data.access_token, expiresAt: now + data.expires_in * 1000};
return cached.token;
}
Was this page helpful?