将变量注入到 Postman Flow 中的 POST JSON 调用中

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

我正在使用邮递员流程进行 POST 调用。我有一个变量,organizationId,我想将其插入到 POST 调用的 JSON 正文中。但我收到以下错误: body:“对象键:值对后的无效字符‘a’”

以下是我的流程:

这是我的 POST 调用的 JSON:

 {
  "title": "Joe's Yearbooks",
  "merchantId": {{organizationId}},
  "description": "Printing yearbooks for 3 decades.",
  "imageUrl": "https://example.com/image.jpg",
  "websiteUrl": "https://www.joeyearbooks.com",
  "support_phone": {
    "countryCode": "1",
    "phoneNumber": "2345678900"
  },
  "support_email": "[email protected]",
  "status": "ACTIVE",
  "organizationIds": [
    "123e4567-e89b-12d3-a456-426614174000"
  ]
}

我在这里遗漏了什么吗?

postman api-design web-api-testing postman-flows
1个回答
0
投票

您的集合中缺少变量“organizationhId”。

步骤

步骤1

访问集合设置:在 Postman 中找到要修改的集合。要访问其设置,请单击位于集合名称左侧的三个点(省略号)菜单。

步骤2

编辑集合:从出现的菜单中选择“编辑”选项。这将在新窗口或选项卡中打开集合的设置。

步骤3

导航到变量:在集合设置窗口中,找到并选择“变量”选项卡。此选项卡专用于管理与此特定集合关联的变量。

步骤4

设置您的变量:在“变量”部分中,在“键”字段中输入变量的名称。例如,键入organizationId 作为键。然后,在相应的“值”字段中,输入您要分配给该变量的值。

这些步骤将指导您完成在 Postman 中添加或修改集合变量的过程,确保您的集合组织良好,并且正确设置变量以满足您的 API 测试需求。

我使用自己的模拟 REST 服务器进行了演示,用于通过 express 库创建组织 POST 调用。

并通过Postman POST请求调用它并且

流程将显示选取“organizationId”并按日志块显示。

服务器代码

另存为“server.js”

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

app.use(express.json());

let organizationIdCounter = 1;

// Endpoint for creating an organization
app.post('/organization', (req, res) => {
    // Extract the body from the request
    const organizationData = req.body;

    // Generate a unique organization ID
    const organizationId = organizationIdCounter++;

    // Add the organizationId to the response
    organizationData.organizationId = organizationId;

    // Send back the organization data with the new organizationId
    res.json(organizationData);
});

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

安装依赖并运行

npm install express
node server.js

邮递员打来的电话

来自 Flows 的调用

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