diff --git a/postman_collection.json b/postman_collection.json index 1ebb462..43e9d6d 100644 --- a/postman_collection.json +++ b/postman_collection.json @@ -28,6 +28,29 @@ "}" ] } + }, + { + "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": {