Files
django-core-base/postman_collection.json
minguezsanzjuanjose 1a53cd3918
All checks were successful
DEPLOY_MULTI_BRACH/pipeline/head This commit looks good
feat: add postrequest script to save access_token in active environment
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-18 14:25:24 +02:00

174 lines
5.7 KiB
JSON

{
"info": {
"name": "Django Core Base API",
"description": "Colección de llamadas para Django Core Base (auth JWT + promociones + automatizados).",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_postman_id": "django-core-base-collection"
},
"variable": [
{ "key": "access_token", "value": "", "type": "string" },
{ "key": "refresh_token", "value": "", "type": "string" }
],
"item": [
{
"name": "Auth",
"item": [
{
"name": "Obtener Token (Login)",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"if (pm.response.code === 200) {",
" const json = pm.response.json();",
" if (json.access) pm.collectionVariables.set('access_token', json.access);",
" if (json.refresh) pm.collectionVariables.set('refresh_token', json.refresh);",
"}"
]
}
},
{
"listen": "postrequest",
"script": {
"type": "text/javascript",
"exec": [
"// Comprobamos si la respuesta es exitosa",
"if (pw.response.status === 200) {",
" // Si el body ya es un objeto no hace falta JSON.parse",
" const body = typeof pw.response.body === 'string'",
" ? JSON.parse(pw.response.body)",
" : pw.response.body;",
"",
" if (body.access) {",
" // Guardamos el token en el entorno actual",
" pw.env.set(\"access_token\", body.access);",
" console.log(\"✅ Token guardado correctamente\");",
" } else {",
" console.log(\"❌ No se encontró el campo 'access' en la respuesta\");",
" }",
"}"
]
}
}
],
"request": {
"method": "POST",
"header": [
{ "key": "Content-Type", "value": "application/json" }
],
"body": {
"mode": "raw",
"raw": "{\n \"username\": \"{{username}}\",\n \"password\": \"{{password}}\"\n}"
},
"url": {
"raw": "{{base_url}}/api/token/",
"host": ["{{base_url}}"],
"path": ["api", "token", ""]
}
}
}
]
},
{
"name": "Promociones",
"item": [
{
"name": "Obtener Promoción",
"request": {
"auth": {
"type": "bearer",
"bearer": [{ "key": "token", "value": "{{access_token}}", "type": "string" }]
},
"method": "POST",
"header": [
{ "key": "Content-Type", "value": "application/json" }
],
"body": {
"mode": "raw",
"raw": "{\n \"id\": 1,\n \"activo\": true\n}"
},
"url": {
"raw": "{{base_url}}/api/promociones/obtener/",
"host": ["{{base_url}}"],
"path": ["api", "promociones", "obtener", ""]
}
}
}
]
},
{
"name": "Automatizados",
"item": [
{
"name": "Ejecutar Automatizaciones",
"request": {
"auth": {
"type": "bearer",
"bearer": [{ "key": "token", "value": "{{access_token}}", "type": "string" }]
},
"method": "POST",
"header": [
{ "key": "Content-Type", "value": "application/json" }
],
"body": {
"mode": "raw",
"raw": "{\n \"nombre\": \"Ejecución manual desde Postman\",\n \"descripcion\": \"Test de las 3 acciones automatizadas\",\n \"origen\": \"manual\"\n}"
},
"url": {
"raw": "{{base_url}}/api/automatizados/ejecutar/",
"host": ["{{base_url}}"],
"path": ["api", "automatizados", "ejecutar", ""]
}
}
},
{
"name": "Historial de Ejecuciones",
"request": {
"auth": {
"type": "bearer",
"bearer": [{ "key": "token", "value": "{{access_token}}", "type": "string" }]
},
"method": "POST",
"header": [
{ "key": "Content-Type", "value": "application/json" }
],
"body": {
"mode": "raw",
"raw": "{\n \"estado\": \"\",\n \"limit\": 20\n}"
},
"url": {
"raw": "{{base_url}}/api/automatizados/historial/",
"host": ["{{base_url}}"],
"path": ["api", "automatizados", "historial", ""]
}
}
},
{
"name": "Estado del Módulo",
"request": {
"auth": {
"type": "bearer",
"bearer": [{ "key": "token", "value": "{{access_token}}", "type": "string" }]
},
"method": "POST",
"header": [
{ "key": "Content-Type", "value": "application/json" }
],
"body": {
"mode": "raw",
"raw": "{}"
},
"url": {
"raw": "{{base_url}}/api/automatizados/estado/",
"host": ["{{base_url}}"],
"path": ["api", "automatizados", "estado", ""]
}
}
}
]
}
]
}