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

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

问题描述

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

{{URL_API}}/products/

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 (the last code is the id of the product, called SKU)

The problem is that if i want to make a CSV in order to update the information of different products i have to define a variable called sku in the endpoint so i will be able to pass the corresponding 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}}

or simply:

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

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

EDIT:

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)

This is what i did:

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.

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.

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.

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.

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天全站免登陆