定义新变量以进行巨大的迭代使我出错 [英] Defining a new variable in order to make a huge iteration giving me an error

查看:94
本文介绍了定义新变量以进行巨大的迭代使我出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个端点,您可以了解有关产品的信息

I have an endpoint, you can have información about products

{{URL_API}} / products /

如果我在该端点上执行GET方法,我将获取每个产品的信息

If i perform a GET method over that endpoint i will obtain the information of every product

但是我也可以指定要想知道,即:

BUT i can also specify the product that i want to know about, i.e:

{{URL_API}} / products / 9345TERFER(最后一个代码是产品的ID,称为SKU)

{{URL_API}}/products/9345TERFER (the last code is the id of the product, called SKU)

问题是,如果我要制作CSV文件以更新不同产品的信息,则必须在端点中定义一个名为sku的变量,这样我才能通过相应的SKU

我要创建变量 {{sku}} ,但是我不知道该怎么做。.我尝试了很多次,但是失败了,我搜索了很多,但是我没有理解

I want to create the variable {{sku}} but i do not understand how to do that.. i tried so many times and i failed, i've searched a lot but i do not really understand

另外,在变量声明前我应该使用:吗?我的意思是:

Also, should i use ":" before the declaration of the variable? i mean:


{{URL_API}} / products /:{{sku}}

{{URL_API}}/products/:{{sku}}

或简单地:


{{URL_API}} / ns / products / {{sku }}

{{URL_API}}/ns/products/{{sku}}

您能帮我吗?
我超级迷路了:(

Can you help me? I'm super lost :(

编辑:

我想执行PUT方法,我想将不同的值传递给正文,然后..发送请求(它引发错误:404错误)

I want to perform a PUT method, i want to pass different values to the body and then.. send the request (it throws an error: 404 not found)

这就是我所做的:

PUT | {{URL_API}} / products / {{sku}}

PUT|{{URL_API}}/products/{{sku}}

body:

{
    "tax_percentage":"{{tax_percentage}}",
    "store_code":"{{store_code}}",
    "markup_top":"{{markup_top}}",
    "status":"{{status}}",
    "group_prices": [
        {
            "group":"{{class_a}}",
            "price":"{{price_a}}",
            "website":"{{website_a}}"
        }
    ]
}

CSV:

邮递员:

推荐答案

您的问题似乎只是对数据文件的基本了解在Postman中使用变量,这是一个简单的示例,对您也将以相同的方式起作用。

Your issue seems to be just a basic understanding of how data files work with variables in Postman, here's a simple example that will work the same way for you too.

这是我用来从变量中解析变量的基本请求数据文件-这是一个GET请求,但没有关系,因为我们在这里仅查看使用数据文件来解析变量。您需要做的就是确保URL正确并且在使用运行程序之前保存请求。

This is a basic request I'm using to resolve the variable from the data file - It's a GET request but that doesn't matter as all we're look at here is using a data file to resolve variables. All you need to do is ensure the URL is correct and that you SAVE the request before using the runner.

这是在文本编辑器中创建的简单CSV文件。在Postman请求中将引用的变量名称上的标题 sku 。该值之下的每个值都是将用于每次迭代的值。

Here's a simple CSV file created in a text editor. The heading sku in the name on the variable it will reference inside the Postman request. Each value under that is the value that will be used for each iteration.

在Runner中,从列表(如果有多个列表),则选择CSV文件。导入后,您将能够查看数据的预览。

In the Runner, select your Collection from the list (If you have more than one) then select the CSV file. Once imported, you will be able to see a preview of the data.

如果正确,请按运行按钮。然后,Runner将遍历文件,并在CSV文件中提取 sku 值,然后在请求中使用它。我已经扩展了其中一个请求,因此您可以看到该值已在请求中使用。

If that's correct, press the Run button. The Runner will then iterate through the file and pick up the sku value in the CSV file and use it in the request. I've expanded one of the requests so you can see that the value was used in the request.

这篇关于定义新变量以进行巨大的迭代使我出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆