Defining a new variable in order to make a huge iteration giving me an error

谁都会走 提交于 2020-05-09 07:05:08

问题


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:


回答1:


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.



来源:https://stackoverflow.com/questions/60878237/defining-a-new-variable-in-order-to-make-a-huge-iteration-giving-me-an-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!