将数据从一个块传递到另一个块作为邮递员工作流程中的请求参数

问题描述 投票:0回答:1

我是邮递员流程的新手,我需要你们的帮助,我正在尝试将数据从一个块传递到另一个块,第一个块成功发送数据,但问题出在第二个块内,但不是正确捕获数据,我将在下面的图片中为您提供整个流程,您可以找到它。在此处输入图像描述

传递的数据是第一个块中 body.responseBody 的值,它是一个字符串“RANDOM12Aw”,需要作为第二个块的请求参数传递。我也会以图片的形式提供第二块API,请查看一下。 在此输入图片描述

如果您看到图片 2,它是块 2 的 API,在键的位置我将其留空,因为它需要从块 1 获取值。这里的问题是键是空的。数据无法正确检索,

期待合适的解决方案或可以解决我的问题的建议。

postman postman-flows
1个回答
0
投票

这个流程会起作用

enter image description here

模拟服务器

demo.js

const express = require('express');
const app = express();
const port = 3000;

app.use(express.json());

app.post('/book-ride', (req, res) => {
    const responseJson = {
        body: {
            responseCode: 201,
            token: null,
            responseMessage: "created successfully.",
            responseBody: "RANBOMwsdw12"
        }
    };

    res.status(201).json(responseJson);
});

app.post('/find-nearby-drivers', (req, res) => {
    // Extract query parameters
    const pickLat = req.query['pickLat'];
    const pickLon = req.query['pickLon'];
    const ruidKey = req.query['ruidKey'];

    // Prepare the data to be returned
    const responseData = {
        'pickLat': pickLat,
        'pickLon': pickLon,
        'ruidKey': ruidKey
    };

    // Send the JSON response
    res.json(responseData);
});

app.listen(port, () => {
    console.log(`Server running on http://localhost:${port}`);
});

安装依赖项

npm install express

运行服务器

node demo.js

定义环境变量

dev

pickLat : 16.99807
pickLon : 82.24365

enter image description here

第一个API

enter image description here

网址

POST http://localhost:3000/book-ride

Tests
选项卡

const jsonData = JSON.parse(responseBody);
console.log("ruidKey: " + jsonData.body.responseBody);
postman.setEnvironmentVariable("ruidKey", jsonData.body.responseBody);

enter image description here

按后发送

ruidKey
变量将通过
RANBOMwsdw12

赋值

enter image description here

第二个API

enter image description here

POST http://localhost:3000/find-nearby-drivers?pickLat={{pickLat}}&pickLon={{pickLon}}&ruidKey={{ruidKey}}

按后发送

enter image description here

创建流程的步骤

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.