邮递员 - 从响应值创建变量

发布于 2025-02-13 12:27:05 字数 743 浏览 1 评论 0原文

也许作为大多数人,我想让我的工作更容易:)

问题:我想知道是否可以根据我的应用程序后端的响应值创建邮递员的变量。

描述:我的应用程序在邮政请求中生成了数据库的对象,它们基于在表单上输入的数据 - 最简单的表单类型!:

Form data:
name: John
surname: Smith

request: POST /apiUser/create
Body/raw:
name=John&surname=Smith

添加对象后,后端正在为此对象生成ID。在Postman中,我在身体中看到了它,这样:

{
    "success": true,
    "data": {
        "id": 4882
    }
}

问题:是否可以从对象的ID创建一个变量?该变量必须存储响应对请求 /apiuser /create生成的ID的值,然后我将创建新的请求 /apiuserimage /uploadimg,这是 - 多亏上述变量 - 将由 /apiuper /create请求在body&gt中生成的cotain ID编号; form-data。

也许有解决此问题的SOM Python程序?

原因:我需要进行上传用户照片的测试,但是为此,我需要在Postman中创建一个新查询:

  1. post- / apiuser / create
  2. post - / apiuserimage / uploadimg

Maybe as most of you I want to make my work easier :)

Problem: I wonder if it is possible to create a variable in Postman, based on the value made by the response from my application backend.

Description: My application generates objects for the database in POST request, they are based on the data entered on the form - the simplest type of form!:

Form data:
name: John
surname: Smith

request: POST /apiUser/create
Body/raw:
name=John&surname=Smith

after adding object, backend is generating ID for this object. In Postman I see it in Body, like this:

{
    "success": true,
    "data": {
        "id": 4882
    }
}

Question: is it possible to create a variable from the ID of the object? The variable must store the value from ID generated by response to request /apiUser/create and then I will create new request /apiUserImage/uploadImg which - thanks to above variable - will cotain ID number generated by /apiUser/create request in Body > form-data.

Or maybe there are som Python programs which handle this?

Why: I need to do a test of uploading user photos, but for this I need to create a new query in postman:

  1. POST - / apiUser / create
  2. POST - / apiUserImage / uploadImg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴我老 2025-02-20 12:27:05

您可以手动创建邮递员中的变量,并将其值分配为您在响应中获得的ID。以下是创建和使用变量的步骤:

  1. 选择环境
  2. 在Globals旁边,选择编辑。
  3. 添加一个名为my_variable的变量,并给它一个初始值nothing yyouwant
  4. 选择 save “保存图标” ,然后关闭“环境”选项卡。
  5. 打开一个新的请求选项卡并输入
    https://postman-echo.com/get? var = ** {{my_variable}}}**作为URL。徘徊
    在变量名称上检查变量的值和范围。

You can manually create a variable in postman and assign it value as the id you get in response. Here are the steps to create and use a variable:

  1. Select the environment enter image description hereat the top right of Postman.
  2. Next to Globals, select Edit.
  3. Add a variable named my_variable and give it an initial value of anythingYouWant.
  4. Select Save Save icon, then close the environment tab.
  5. Open a new request tab and enter
    https://postman-echo.com/get?var=**{{my_variable}}** as the URL. Hover
    over the variable name to inspect the variable's value and scope.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文